I have a gulp.task 'scripts'
that uses gulp-uglify
. Then I also added gulp-import
and it didn't work. If i do only uglify
it works. If I do only import
it works. But if i do both at the same time it doesn't work.
Here is the function:
gulp.task('scripts', function(){
gulp.src([
'testgulp/**/*.js', '!testgulp/**/_*.js', '!testgulp/**/*.min.js'
])
.pipe(include()) //if I ment only this line, uglify works
.on('error', console.log)
.pipe(uglify()) //if I ment only this line, include works
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(function(file) { return file.base; }));
});
And then on terminal I have this response when try to do both:
/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)
I'm moving away from Koala App and the append/prepend feature was awesome, so i would like to do the same with Gulp. I tried gulp-include and gulp-import, both has the same problem. What i'm doing wrong? Thank you :)
-EDIT- i also tried gulp-sync and hardcode a timeout() on minifyit task, but doesn't fix the problem...
I have a gulp.task 'scripts'
that uses gulp-uglify
. Then I also added gulp-import
and it didn't work. If i do only uglify
it works. If I do only import
it works. But if i do both at the same time it doesn't work.
Here is the function:
gulp.task('scripts', function(){
gulp.src([
'testgulp/**/*.js', '!testgulp/**/_*.js', '!testgulp/**/*.min.js'
])
.pipe(include()) //if I ment only this line, uglify works
.on('error', console.log)
.pipe(uglify()) //if I ment only this line, include works
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(function(file) { return file.base; }));
});
And then on terminal I have this response when try to do both:
/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)
I'm moving away from Koala App and the append/prepend feature was awesome, so i would like to do the same with Gulp. I tried gulp-include and gulp-import, both has the same problem. What i'm doing wrong? Thank you :)
-EDIT- i also tried gulp-sync and hardcode a timeout() on minifyit task, but doesn't fix the problem...
Share Improve this question edited Aug 21, 2016 at 19:41 sandrina-p asked Aug 21, 2016 at 18:02 sandrina-psandrina-p 4,1709 gold badges37 silver badges66 bronze badges3 Answers
Reset to default 6Okay, I think I found the problem. First of all I needed to install gulp-util to find out better what was the error.
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; }));
});
Then it was something with ES5 shorthand uglify that trows an error. I had to install gulp-babel as well, and the final code:
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
pact: true
}))
.pipe(uglify().on('error', gutil.log)) // gulp-util
.pipe(rename({ suffix: '.min' }))
});
And that fixed my problem. Hope to help someone else :)
You should use pump module.
var pump = require('pump');
gulp.task('scripts', function(){
pump([
gulp.src([...]),
ugilfy(),
rename({ suffix: '.min' }),
gulp.dest(...)
]);
});
And you can see why use pump
Just have them as separate functions and have the include one run before the uglify one:
gulp.task('include,function({
// include code here
});
gulp.task('uglify',['include'],function({
// uglify code here
});
the include function between the [] will run before the uglify function when you run the uglify function
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745461213a4628716.html
评论列表(0条)