Having a problem with a gulp and js file minifications, gulp makes 3 times bigger files.
For example lightgallery.min.js - 49kb (downloaded from GitHub) then I download the same file via npm and required in js file (same if I insert downloaded file content from github)
global.lightgallery = require('lightgallery');
and run gulp it makes file 133kb
GULP TASK
gulp.task('scripts', function() {
gulp.src( SOURCEPATHS.jsSource )
.pipe( browserify() )
.pipe( uglify() )
.pipe( rename({ extname: '.min.js' }) )
.pipe( gulp.dest(APPPATH.js) );
});
Not using any sourcemaps.
Maybe someone was having the same problem?
A gulpfile is a file in your project directory titled gulpfile. js (or capitalized as Gulpfile. js , like Makefile), that automatically loads when you run the gulp command.
Gulp used JavaScript configuration code which was less verbose, easier to read, simpler to modify, and provided better flexibility. Gulp was faster because it used Node. js streams to pass data through a series of piped plugins. Files were only written at the end of each task.
Declare Dependencies and Create Tasks gulp. task('clean:build', function() { return del. sync('build'); }); The above task will clean entire build. The clean task clears any image catches and removes any old files present in build.
The package lightgallery
has a dependency of jQuery as specified on the npm description and in its package.json. When Browserify does its thing, it checks the dependency graph of the package and pulls everything in. jQuery v3.3.1 minified is around ~85kb which should account for the discrepancy.
In case you already have jQuery somewhere else, you can usually get Browserify to ignore that particular package. For example, using the gulp-browserify
package:
.pipe(browserify({ ignore: 'jquery' }))
Update
You can selectively apply this to files using the gulp-if plugin:
.pipe(
gulpif(
'jquery.js',
browserify(),
browserify({ ignore: ['jquery'] })
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With