我有gulp.task 'scripts'
使用gulp-uglify
。然后我还添加了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)
我正在离开考拉应用程序并且附加/前置功能非常棒,所以我想对Gulp做同样的事情。我尝试了gulp-include和gulp-import,两者都有同样的问题。我做错了什么? 谢谢:))
- 编辑 - 我也试过gulp-sync并在minifyit任务上硬编码超时(),但是没有解决问题......
答案 0 :(得分:5)
好的,我想我发现了这个问题。 首先,我需要安装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简写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' }))
});
这解决了我的问题。 希望能帮助别人:)
答案 1 :(得分:1)
您应该使用泵模块。
DECLARE @testdate DATETIME
SELECT @testdate = '2016-08-23'
SELECT LEFT (CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@testdate)-1),@testdate),113),6)
+' to '+LEFT(CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@testdate))),
DATEADD(mm,1,@testdate)),113),11) AS Date_Value
您可以看到why use pump
答案 2 :(得分:0)
将它们作为单独的函数,并在uglify之前包含一个运行:
gulp.task('include,function({
// include code here
});
gulp.task('uglify',['include'],function({
// uglify code here
});
运行uglify函数时,[]之间的include函数将在uglify函数之前运行