为什么 uglify 无法处理 AngularJS 内容?
Why is uglify not working on AngularJS content?
我构建了一些 gulp 任务来帮助构建我的网络项目。其中之一,我正在缩小 js 文件。这是任务:
gulp.task('minify' , function() {
console.log('Copy minified js ');
return gulp.src('dist/www/**/*.js'])
.pipe(uglify().on('error', function(e){
console.log(e);
}))
.pipe(gulp.dest('dist/www'));
});
当我执行任务时:gulp minify
我收到以下错误:
{ [Error: E:XXXXXX\dist\tmp\bootstrap.js: SyntaxError: Unexpected token: name (mainModule)]
message: 'E:XXXXXX\dist\tmp\bootstrap.js: SyntaxError: Unexpected token: name (mainModule)',
fileName: 'E:XXXXXX\dist\bootstrap.js',
lineNumber: 1,
stack: 'Error\n at new JS_Parse_Error (eval at <anonymous> (E:XXXXXX\gfgfgfgf\gulp-uglify\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:1534:18)\n at js_error (eval at <anonymous> (
这里是 bootstrap.js 文件:
import mainModule from './src/main';
angular.element(document).ready(function() {
angular.bootstrap(document, [mainModule.name], { strictDi: true });
});
发生了什么事?有人可以帮助我解释为什么它不起作用吗?
谢谢!
在丑化Angular组件之前,您需要添加Angular依赖注入注解。在通过 uglify 进行管道传输之前,您可以通过管道传输 ng-annotate。
编辑:此外,uglifying ES6 javascript. If you are using ES6 syntax, you should pipe your code through Babel 在丑化之前存在已知问题。
希望对您有所帮助!
我构建了一些 gulp 任务来帮助构建我的网络项目。其中之一,我正在缩小 js 文件。这是任务:
gulp.task('minify' , function() {
console.log('Copy minified js ');
return gulp.src('dist/www/**/*.js'])
.pipe(uglify().on('error', function(e){
console.log(e);
}))
.pipe(gulp.dest('dist/www'));
});
当我执行任务时:gulp minify
我收到以下错误:
{ [Error: E:XXXXXX\dist\tmp\bootstrap.js: SyntaxError: Unexpected token: name (mainModule)]
message: 'E:XXXXXX\dist\tmp\bootstrap.js: SyntaxError: Unexpected token: name (mainModule)',
fileName: 'E:XXXXXX\dist\bootstrap.js',
lineNumber: 1,
stack: 'Error\n at new JS_Parse_Error (eval at <anonymous> (E:XXXXXX\gfgfgfgf\gulp-uglify\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:1534:18)\n at js_error (eval at <anonymous> (
这里是 bootstrap.js 文件:
import mainModule from './src/main';
angular.element(document).ready(function() {
angular.bootstrap(document, [mainModule.name], { strictDi: true });
});
发生了什么事?有人可以帮助我解释为什么它不起作用吗?
谢谢!
在丑化Angular组件之前,您需要添加Angular依赖注入注解。在通过 uglify 进行管道传输之前,您可以通过管道传输 ng-annotate。
编辑:此外,uglifying ES6 javascript. If you are using ES6 syntax, you should pipe your code through Babel 在丑化之前存在已知问题。
希望对您有所帮助!