gpt4 book ai didi

javascript - gulp-include 和 gulp-uglify 不起作用

转载 作者:行者123 更新时间:2023-11-29 16:06:56 24 4
gpt4 key购买 nike

我有一个使用 gulp-uglifygulp.task 'scripts'。然后我还添加了 gulp-import 也没有用。如果我只做 uglify 就可以了。如果我只执行 import 它就可以了。但是,如果我同时进行这两项操作,那是行不通的。这是函数:

gulp.task('scripts', function(){
gulp.src([
'testgulp/**/*.js', '!testgulp/**/_*.js', '!testgulp/**/*.min.js'
])
.pipe(include()) //if I comment only this line, uglify works
.on('error', console.log)
.pipe(uglify()) //if I comment only this line, include works
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(function(file) { return file.base; }));

});

然后在终端上,当我尝试同时执行这两项操作时,我得到了这个响应:

/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/map-stream/index.js:103
throw err
^
GulpUglifyError: unable to minify JavaScript
at createError (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/gulp-uglify/lib/create-error.js:6:14)
at wrapper (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/gulp-uglify/node_modules/lodash/_createHybrid.js:87:15)
at trycatch (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/gulp-uglify/minifier.js:26:12)
at DestroyableTransform.minify [as _transform] (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/gulp-uglify/minifier.js:76:19)
at DestroyableTransform.Transform._read (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
at DestroyableTransform.Transform._write (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
at doWrite (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64)
at writeOrBuffer (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5)
at DestroyableTransform.Writable.write (/Applications/MAMP/htdocs/git/personal-sandrina-p/_main/v3/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:241:11)
at Stream.ondata (stream.js:31:26)

我正在远离 Koala 应用程序,附加/前置功能非常棒,所以我想对 Gulp 做同样的事情。我尝试了 gulp-include 和 gulp-import,两者都有同样的问题。我做错了什么?谢谢:)

-编辑-我还在 minifyit 任务上尝试了 gulp-sync 和硬编码超时(),但没有解决问题......

最佳答案

好的,我想我找到了问题所在。首先,我需要安装 gulp-util 以更好地找出错误所在。

gulp.task('scripts', function(){
gulp.src([
'assets/scripts/**/*.js',
'!assets/scripts/**/_*.js',
'!assets/scripts/**/*.min.js'
])
.pipe(include())
.on('error', console.log)
.pipe(uglify().on('error', gutil.log)) //gulp-util
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(function(file) { return file.base; }));
});

然后是 ES5 shorthand uglify 抛出了一个错误。我还必须安装 gulp-babel,最后的代码:

gulp.task('scripts', function(){
gulp.src([
'assets/scripts/**/*.js',
'!assets/scripts/**/_*.js',
'!assets/scripts/**/*.min.js'
])
.pipe(include())
.on('error', console.log)
.pipe(babel({
presets: ['es2015'], //this fixed a shorthand javascript error
compact: true
}))
.pipe(uglify().on('error', gutil.log)) // gulp-util
.pipe(rename({ suffix: '.min' }))
});

这解决了我的问题。希望能帮助别人:)

关于javascript - gulp-include 和 gulp-uglify 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39067275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com