• <bdo id='RMi6H'></bdo><ul id='RMi6H'></ul>
  • <small id='RMi6H'></small><noframes id='RMi6H'>

      1. <i id='RMi6H'><tr id='RMi6H'><dt id='RMi6H'><q id='RMi6H'><span id='RMi6H'><b id='RMi6H'><form id='RMi6H'><ins id='RMi6H'></ins><ul id='RMi6H'></ul><sub id='RMi6H'></sub></form><legend id='RMi6H'></legend><bdo id='RMi6H'><pre id='RMi6H'><center id='RMi6H'></center></pre></bdo></b><th id='RMi6H'></th></span></q></dt></tr></i><div id='RMi6H'><tfoot id='RMi6H'></tfoot><dl id='RMi6H'><fieldset id='RMi6H'></fieldset></dl></div>
        <legend id='RMi6H'><style id='RMi6H'><dir id='RMi6H'><q id='RMi6H'></q></dir></style></legend>

      2. <tfoot id='RMi6H'></tfoot>

        无法使用 browserify 和 debowerify 获取外部库

        时间:2023-05-29

            <i id='eovY1'><tr id='eovY1'><dt id='eovY1'><q id='eovY1'><span id='eovY1'><b id='eovY1'><form id='eovY1'><ins id='eovY1'></ins><ul id='eovY1'></ul><sub id='eovY1'></sub></form><legend id='eovY1'></legend><bdo id='eovY1'><pre id='eovY1'><center id='eovY1'></center></pre></bdo></b><th id='eovY1'></th></span></q></dt></tr></i><div id='eovY1'><tfoot id='eovY1'></tfoot><dl id='eovY1'><fieldset id='eovY1'></fieldset></dl></div>

            <small id='eovY1'></small><noframes id='eovY1'>

          1. <legend id='eovY1'><style id='eovY1'><dir id='eovY1'><q id='eovY1'></q></dir></style></legend>

            • <bdo id='eovY1'></bdo><ul id='eovY1'></ul>

              1. <tfoot id='eovY1'></tfoot>
                  <tbody id='eovY1'></tbody>
                  本文介绍了无法使用 browserify 和 debowerify 获取外部库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我的手很头疼.这是我当前的设置:

                  I have a headache on my hands. Here's my current setup:

                  • 获取供应商库(在本例中为 Angular)
                  • 运行 browserify 的 gulp 任务
                  • debowerify 使 bower 库与 browserify 兼容

                  App.js(在 browserify 之前):

                  'use strict';
                  
                  var angular = require("angular");
                  var Routes = require("./routes");
                  
                  angular.module('MyAngularApp')
                    .config(Routes);
                  

                  App.js(在 browserify 之后/在 bundle.js 中):

                  var angular = require("./../ext/angular/angular.js");
                  var Routes = require("./routes");
                  
                  angular.module('MyAngularApp')
                    .config(Routes);
                  

                  到目前为止一切都很好,对吧?似乎 debowerify 完成了它的工作,并将 angular 替换为来自 bower 的 angular.js 的相对路径.

                  So far so good, right? It seems like debowerify did it's job and replaced the angular with the relative path to the angular.js from bower.

                  但是当我在浏览器命令行中调试 bundle.js 时,在执行了前两行 require 之后(对于 angularRoutes),angular 是一个空 obj,但 Routes 正是我在导出中设置的正确函数.

                  But when I debug the bundle.js in the browser command line, after executing the first two require lines (for angular and Routes), angular is an empty obj, but Routes is exactly the correct function that I setup in the export.

                  问题:为什么使用 require 函数不能正确导入 angular?

                  Question: Why isn't angular being imported correctly using the require function?

                  我将它放入我的 package.json 以使 debowerify 工作:

                  I put this into my package.json to get the debowerify working:

                    "browserify": {
                      "transform": [
                        "debowerify"
                      ]
                    },
                  

                  推荐答案

                  AngularJS 目前不支持 CommonJS,所以 var angular = require("angular") 不起作用.而不是它,只使用 require('angular').

                  AngularJS doesn't support CommonJS at the moment, so var angular = require("angular") doesn't work. Instead of it, use just require('angular').

                  'use strict';
                  
                  require('angular');
                  var Routes = require("./routes");
                  
                  angular.module('MyAngularApp')
                    .config(Routes);
                  

                  Angular 对象将被全局加载,它也将能够被其他 JS 文件访问.

                  The Angular object will be loaded globally and it'll be able to be accessed by other JS files, too.

                  这篇关于无法使用 browserify 和 debowerify 获取外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 gulp 任务中删除文件 下一篇:在 React JS 中需要带有变量的文件

                  相关文章

                  最新文章

                  <small id='faOkg'></small><noframes id='faOkg'>

                  <tfoot id='faOkg'></tfoot>
                  <i id='faOkg'><tr id='faOkg'><dt id='faOkg'><q id='faOkg'><span id='faOkg'><b id='faOkg'><form id='faOkg'><ins id='faOkg'></ins><ul id='faOkg'></ul><sub id='faOkg'></sub></form><legend id='faOkg'></legend><bdo id='faOkg'><pre id='faOkg'><center id='faOkg'></center></pre></bdo></b><th id='faOkg'></th></span></q></dt></tr></i><div id='faOkg'><tfoot id='faOkg'></tfoot><dl id='faOkg'><fieldset id='faOkg'></fieldset></dl></div>
                    <bdo id='faOkg'></bdo><ul id='faOkg'></ul>

                  <legend id='faOkg'><style id='faOkg'><dir id='faOkg'><q id='faOkg'></q></dir></style></legend>