admin 管理员组文章数量: 1086019
I am currently refactoring a project where previously all of the minified JavaScript files were being placed in a specific directory. Now I need to the minified versions to stay in the same directories as their source files.
Currently I do this:
gulp.task( 'scripts', function () {
return gulp.src( source_paths.scripts )
.pipe( uglify( {
preserveComments: 'false'
} ) )
.pipe( rename( {suffix: ".min"} ) )
.pipe( gulp.dest( './build/js' ) )
.pipe( notify( {
message: 'Scripts task plete!',
onLast : true
} ) );
} );
This works, except it moves my files. I tried changing my use of gulp.dest()
to .pipe( gulp.dest( '' ) )
as well as just removing that line. In both cases no minified JS was written and I was very sad.
How can I make it write all files to the same directory as their source files?
I am currently refactoring a project where previously all of the minified JavaScript files were being placed in a specific directory. Now I need to the minified versions to stay in the same directories as their source files.
Currently I do this:
gulp.task( 'scripts', function () {
return gulp.src( source_paths.scripts )
.pipe( uglify( {
preserveComments: 'false'
} ) )
.pipe( rename( {suffix: ".min"} ) )
.pipe( gulp.dest( './build/js' ) )
.pipe( notify( {
message: 'Scripts task plete!',
onLast : true
} ) );
} );
This works, except it moves my files. I tried changing my use of gulp.dest()
to .pipe( gulp.dest( '' ) )
as well as just removing that line. In both cases no minified JS was written and I was very sad.
How can I make it write all files to the same directory as their source files?
Share Improve this question edited Mar 1, 2016 at 14:43 scniro 17k8 gold badges66 silver badges107 bronze badges asked Mar 1, 2016 at 4:26 JPollockJPollock 3,5584 gold badges27 silver badges37 bronze badges 1- What's the difference between your question and this one? – gideonite Commented Mar 1, 2016 at 4:30
2 Answers
Reset to default 8You're currently writing to build/js
, and of course removing the dest
results in no files written. As ments suggest, you can call file.base
in an anonymous function in your dest
call. Observe the following...
// fixed spacing madness
gulp.task('scripts', function () {
return gulp.src(source_paths.scripts)
.pipe(uglify({
preserveComments: 'false'
})
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(function(file) {
return file.base;
}))
.pipe(notify({
message: 'Scripts task plete!',
onLast : true
}));
});
USE " ./ " ... current location
gulp.task('task_name', function () {
return gulp.src(path\*.js) // or other selection
.pipe(uglify())
.pipe(rename({suffix: '.min'})).pipe(gulp.dest("./"));
});
本文标签: javascriptGulpMinify JS and write to same destinationStack Overflow
版权声明:本文标题:javascript - Gulp - Minify JS and write to same destination - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744079503a2529971.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论