问题描述
我有我的手很头疼。下面是我的当前设置:
- 亭子得到厂商库(在此情况下的角)
- 一饮而尽任务运行browserify
- debowerify使凉亭库与browserify兼容
App.js(前browserify):
使用严格的;VAR角=要求(角);
VAR路线=要求(./路线);angular.module('MyAngularApp')
的.config(路线);
App.js(后browserify /在bundle.js):
VAR角=要求(./../转/角/ angular.js);
VAR路线=要求(./路线);angular.module('MyAngularApp')
的.config(路线);
到目前为止好,对不对?好像debowerify做它的工作,取代了角
从亭子到 angular.js
的相对路径。
但是,当我调试 bundle.js
在浏览器命令行中,执行前两个要求
行之后(对于角
和路线
),角
是一个空OBJ,但路线
是完全正确的功能,我设置的出口。
问:为什么不是角
使用要求
函数正确导入?
我把这个我的的package.json
来获得 debowerify
工作
browserify:{
转变: [
debowerify
]
},
AngularJS目前不支持CommonJS的,所以 VAR角=要求(角)
不工作。取而代之的是,只用要求('角')
。
使用严格的;需要('角');
VAR路线=要求(./路线);angular.module('MyAngularApp')
的.config(路线);
该角对象将在全球范围内加载,这将能够通过其他的JS文件进行访问了。
I have a headache on my hands. Here's my current setup:
- bower to get vendor libraries (angular in this case)
- gulp task to run browserify
- debowerify to make the bower libraries compatible with browserify
App.js (before browserify):
'use strict';
var angular = require("angular");
var Routes = require("./routes");
angular.module('MyAngularApp')
.config(Routes);
App.js (after browserify/in the bundle.js):
var angular = require("./../ext/angular/angular.js");
var Routes = require("./routes");
angular.module('MyAngularApp')
.config(Routes);
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.
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.
Question: Why isn't angular
being imported correctly using the require
function?
I put this into my package.json
to get the debowerify
working:
"browserify": {
"transform": [
"debowerify"
]
},
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);
The Angular object will be loaded globally and it'll be able to be accessed by other JS files, too.
这篇关于无法获得外部库browserify和debowerify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!