我的手很头疼.这是我当前的设置:
I have a headache on my hands. Here's my current setup:
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 之后(对于 angular 和 Routes),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模板网!
Browserify,Babel 6,Gulp - 传播运算符上的意外令牌Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 传播运算符上的意外令牌)
是否可以将标志传递给 Gulp 以使其以不同的方式Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以将标志传递给 Gulp 以使其以不同的方式运行任务
为什么我们需要在全局和本地安装 gulp?Why do we need to install gulp globally and locally?(为什么我们需要在全局和本地安装 gulp?)
如何一个接一个地依次运行 Gulp 任务How to run Gulp tasks sequentially one after the other(如何一个接一个地依次运行 Gulp 任务)
打开 Javascript 文件时 Visual Studio 2015 崩溃Visual Studio 2015 crashes when opening Javascript files(打开 Javascript 文件时 Visual Studio 2015 崩溃)
检测 FLASH 插件崩溃Detect FLASH plugin crashes(检测 FLASH 插件崩溃)