当我尝试使用bowserify,angularjs和coffeescript时,我遇到了一个问题.
事实上,当我尝试要求(‘angular’)时,我得到一个空对象:
angular = require('angular') console.log angular ## return an empty object {} configuration = require('../../config/config') console.log configuration ## returns my fully config file correctly
我不知道为什么在这种情况下它不能正常工作: – /.
这是我的package.json,其中我放置了我的个人角度依赖项:
{ "dependencies": { "gulp": "*","gulp-browserify": "*","coffeeify": "*","gulp-concat": "*" },"browser": { "angular": "./app/core/angular-libs/angular.min.js","angular-route": "./app/core/angular-libs/angular-route.min.js","angular-animate": "./app/core/angular-libs/angular-animate.min.js" } }
这是我的gulp文件,它在dest文件夹中生成我的bundle.js:
var gulp = require('gulp'); var browserify = require('gulp-browserify'); var concat = require('gulp-concat'); gulp.task('scripts',function () { return gulp.src('app/**/*.coffee',{ read: false }) .pipe(browserify({ transform: ['coffeeify'],extensions: ['.coffee'] })) .pipe(concat('bundle.js')) .pipe(gulp.dest('./dest/')); }); gulp.task('default',function () { gulp.run('scripts'); });
你能帮助我吗 ? : – /
谢谢你提前
解决方法
Angular 1不支持CommonJS模块,因此它“导出”一个空对象.
相反,只需要它(不指定结果):
require('angular')
这将角度附加到全局对象.
更新:As of Angular 1.3.14,require(‘angular’)现在返回角度对象.