Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp minify and don't copy original files

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));
});
like image 345
Robin Andrews Avatar asked Apr 18 '18 16:04

Robin Andrews


People also ask

How to minify HTML files with gulp?

the minfied HTML files are output to the declared destination. The below code first declares a new gulp task, ‘gulp clean’, which deletes everything in the output folder (this is to ensure that only the required files are in the output folder). The code then declares a task, ‘gulp default’, which runs the minification tasks in sequence: 4.

What is gulp-minify plugin?

The gulp-minify plugin minifies JS files. The resulting files are lighter. The minified files have the -min.js extension. We initiate a Node.js project and install Gulp and gulp-minify plugin. We initiate a Node project and install Gulp and Gulp CLI.

How to minify Node JS using gulp?

Once you have installed Node.js on your computer, you need to create a file called package.json and declare the npm packages that will be used for the minification process. Copy and paste the code below into your package.json file: 3. Create a ‘gulpfile.js’ file and add the required code Next, create a file called gulpfile.js.

How do I use Gulp in Visual Studio?

To use gulp, you need to create a file called gulpfile.js and save it at the root of your project. Do that first. Then paste the following into that file: Your default task will run, and you should see some output similar to this:


Video Answer


1 Answers

Set the noSource config like the following

  .pipe(minify({noSource: true})
like image 69
GSSwain Avatar answered Oct 02 '22 16:10

GSSwain