gulp压缩代码的问题?
14:13:13] Starting 'agency:build'...
events.js:183
throw er; // Unhandled 'error' event
^
Error
at new JS_Parse_Error (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:1534:18)
at js_error (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:1542:11)
at croak (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2089:9)
at token_error (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2097:9)
at expect_token (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2110:9)
at expect (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2113:36)
at regular_for (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2354:9)
at for_ (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2350:16)
at eval (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2229:24)
at eval (eval at <anonymous> (D:\0410\wenjian2\gameSystem\node_modules\_uglify-js@2.6.4@uglify-js\tools\node.js:28:1), <anonymous>:2136:24)
其中agencySource...后面的是路径,压缩代码的时候报错,不知道该怎么压缩代码了?
gulp.task('agency:cache-templates', function() {
var options = {
removeComments: true, //清除HTML注释
collapseWhitespace: true, //压缩HTML
collapseBooleanAttributes: false, //省略布尔属性的值 <input checked="true"/> ==> <input />
removeEmptyAttributes: true, //删除所有空格作属性值 <input id="" /> ==> <input />
removeScriptTypeAttributes: true, //删除<script>的type="text/javascript"
removeStyleLinkTypeAttributes: true, //删除<style>和<link>的type="text/css"
minifyJS: true, //压缩页面JS
minifyCSS: true //压缩页面CSS
};
return gulp.src([agencySource.js.staticViews, agencySource.js.views])
.pipe(htmlmin(options))
.pipe(templateCache('app.js', {
root: 'views',
module: 'app'
}))
.pipe(gulp.dest(agencySource.build.cache));
});
gulp.task('agency:build', ['agency:cache-templates'], function() {
agencySource.js.src.push(agencySource.build.cache + '/app.js');
return gulp.src(agencySource.js.src)
.pipe(ngAnnotate())
//.pipe(uglify())
.pipe(concat('app.js'))
.pipe(gulp.dest(agencySource.build.cache));
});
我在 `https://www.npmjs.com/package/gulp-uglify`中找到了,但是不知道怎么用?
var uglifyjs = require('uglify-js'); // can be a git checkout
// or another module (such as `uglify-es` for ES6 support)
var composer = require('gulp-uglify/composer');
var pump = require('pump');
var minify = composer(uglifyjs, console);
gulp.task('compress', function (cb) {
// the same options as described above
var options = {};
pump([
gulp.src('lib/*.js'),
minify(options),
gulp.dest('dist')
],
cb
);
});
大佬们帮我看看、、、、谢谢!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
见https://www.npmjs.com/package...
不压缩,运行gulp有问题吗?应该是你之前写的代码里面格式有问题,但是gulp不会提醒是哪里报错了,安装elist检查一下,兄弟你这工作量会有点大