我正在使用laravel 5.1 elixer来管理,版本,缩小我的应用程序css和js
以下是我的gulpfile.js
elixir(function (mix) {
mix.less([
'app.less',
'creative.less',
'mixins.less',
'variables.less'
]).less([
'dashboard.less',
'component.less',
'app-variables.less'
], 'public/css/dashboard.css')
mix.scriptsIn('public/js/angular/controller', 'public/js/angular/appControllers.min.js');
mix.scriptsIn('public/js/angular/service', 'public/js/angular/appServices.min.js');
mix.scriptsIn('public/js/angular/directive', 'public/js/angular/appDerictives.min.js');
mix.version([
'public/css/dashboard.css',
'public/css/app.css',
'public/js/angular/appControllers.min.js',
'public/js/angular/appServices.min.js',
'public/js/angular/appDerictives.min.js'
]);
});
当我运行命令gulp
时,一切正常,我得到编译的文件,版本文件现在也在构建文件夹中。
问题在我使用gulp --production
时开始,当laravel启动时,进程在使用脚本启动时中断,下面是错误 -
events.js:141
throw er; // Unhandled 'error' event
^
Error at new JS_Parse_Error (eval at <anonymous (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18)
at js_error (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11)
at croak (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2089:9)
at token_error (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2097:9)
at unexpected (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2103:9)
at expr_atom (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2630:9)
at maybe_unary (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2792:19)
at expr_ops (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2827:24)
at maybe_conditional (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2832:20)
at maybe_assign (eval at <anonymous> (/Users/apple/code/hireajackal/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2856:20)
问题肯定在于gulp文件的scriptsIn
部分,或者我可以说gulp无法缩小js文件。
我试过通过多种方式调试这个,但仍然无法找到问题。试图更新/降级相关的软件包,但即使这样也无济于事。
任何帮助都将不胜感激。
答案 0 :(得分:0)
只需在一个旧的Laravel 5.1项目中进行这项工作即可。
这似乎主要是由于您添加了uglyfijs无法解析的一些新ECMAScript 6+代码引起的。要解决此问题,您需要使用buble或babel在运行gulp时自动转换代码,或将有问题的代码更改为“常规” js。
看到此问题:https://github.com/JeffreyWay/laravel-elixir-webpack-official/issues/34
在运行gulp时使用babel自动转换代码:
来源:https://laravel.com/docs/5.1/elixir#babel
elixir(function(mix) {
mix.babel([
'order.js',
'product.js'
]);
});
或修复您的代码,使用以下命令找出导致问题的脚本:
./node_modules/.bin/uglifyjs path/to/resources/assets/js/some_script.js
对每个脚本执行此操作,直到抱怨为止。如果抛出错误,则会将您指向行号。