我设置并运行gulp任务来创建一个Angular应用程序,它运行没有错误并正确创建文件,但是当我在浏览器上加载页面时,我收到以下错误消息.
有没有一些步骤或一些插件,我没有得到角度文件的所有“工作”?我已经使用了angularFilesort()和ngAnnotate()插件.
var bower = gulp.src(bower_files) .pipe(concat("bower-expanded.js")) .pipe(gulp.dest(paths.prod)) .pipe(rename("bower.js")) .pipe(uglify()) .pipe(gulp.dest(paths.prod + paths.js)); // gather and compress the app's js files var app = gulp.src(paths.source + "app/**/*.js") .pipe(angularFilesort()) .pipe(concat("app-expanded.js")) .pipe(ngAnnotate({ add: true,single_quotes: true })) .pipe(gulp.dest(paths.prod)) .pipe(rename("app.js")) .pipe(uglify()) .pipe(gulp.dest(paths.prod + paths.js));
错误是
TypeError: (intermediate value)(...) is not a function (function(angular) {
它们指向这些代码行
(function(angular) { 'use strict'; /** * Called with an array this acts like map,otherwise it acts like _.mapValues * in lodash. * @return {Array|Object} The same type as the input argument. */ var mapValues = function(obj,callback) { if (angular.isArray(obj))
另一个错误是
Error: [$injector:modulerr] Failed to instantiate module app due to: [$injector:modulerr] Failed to instantiate module angularSpinner due to: [$injector:nomod] Module 'angularSpinner' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.4.4/$injector/nomod?p0=angularSpinner
解决方法
我注意到您没有在您的保镖组件上运行ngAnnotate,但是您正在运行uglify.这可能会导致您的问题.
尝试:
var bower = gulp.src(bower_files) .pipe(concat("bower-expanded.js")) .pipe(ngAnnotate({ add: true,single_quotes: true })) .pipe(gulp.dest(paths.prod)) .pipe(rename("bower.js")) .pipe(uglify()) .pipe(gulp.dest(paths.prod + paths.js));
除此之外,将所有依赖项连接到一个文件中并不是一件好主意.浏览器可以异步加载多个JS文件,并且比加载单个大规模JS文件要快得多.