最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Gulp minify and don't copy original files - Stack Overflow

programmeradmin8浏览0评论

I want to minify some JS files with Gulp, but can't seem to get control over the process. I want only the minified version in the destination, and am currently getting copies of the originals as well.

I'm thinking I may need the rename package, but am not sure how to use it for this task - I would presumably need some kind of variable to hold the current file name for each script.

Any help much appreciated. The code is below:

var gulp = require( 'gulp' );
var minify = require( 'gulp-minify' );
var rename = require( 'gulp-rename' );

//script paths
var jsFiles = 'js/**/*.js',
    jsDest = 'js/dist/';

gulp.task('scripts', function() {
    return gulp.src(jsFiles)
        .pipe(minify())
        .pipe(gulp.dest(jsDest));
});

I want to minify some JS files with Gulp, but can't seem to get control over the process. I want only the minified version in the destination, and am currently getting copies of the originals as well.

I'm thinking I may need the rename package, but am not sure how to use it for this task - I would presumably need some kind of variable to hold the current file name for each script.

Any help much appreciated. The code is below:

var gulp = require( 'gulp' );
var minify = require( 'gulp-minify' );
var rename = require( 'gulp-rename' );

//script paths
var jsFiles = 'js/**/*.js',
    jsDest = 'js/dist/';

gulp.task('scripts', function() {
    return gulp.src(jsFiles)
        .pipe(minify())
        .pipe(gulp.dest(jsDest));
});
Share Improve this question edited May 27, 2018 at 13:02 Jan Bodnar 11.7k6 gold badges71 silver badges83 bronze badges asked Apr 18, 2018 at 16:08 Robin AndrewsRobin Andrews 3,80412 gold badges55 silver badges128 bronze badges 1
  • The minified files are written under js/**/*.js too ???? – Alejandro Teixeira Muñoz Commented Apr 18, 2018 at 16:12
Add a ment  | 

1 Answer 1

Reset to default 12

Set the noSource config like the following

  .pipe(minify({noSource: true})
发布评论

评论列表(0)

  1. 暂无评论