Most of the questions and answers on this topic are two or more years old. Are developers minifying
js another way now?
I keep getting errors when running my gulp script (below) - I did install each plugin beforehand.
var gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify');
.
.
.
gulp.task('minify', async function() {
gulp.src('./dev/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('production/js'));
});
I used async to fix warnings I was getting.
I also tried without async and using: return gulp.src('./dev/js/*.js')
The errors are:
$ gulp minify
assert.js:350
throw err;
^
AssertionError [ERR_ASSERTION]: Task never defined: js
at getFunction (C:\Users\Ted\Documents\Web Development\javaScript &
JQuery\Gulp People
Objects\node_modules\undertaker\lib\helpers\normalizeArgs.js:15:5)
When installing the uglify plugin I am also getting warnings such as:
- gulp-uglify@3.0.1 added 6 packages from 41 contributors and audited 7528 packages in 6.424s found 5 vulnerabilities (3 low, 1 high, 1 critical) run
npm audit fix
to fix them, ornpm audit
for details
Is there a safer tool I could be using?
I've just begun learning gulp and am trying to practice (but it's not going all that well!)
Thanks.
npm audit fix
checks for the packages that are out-of-date and updates it.
In order to compress JS, gulp-uglify
is a good package.
I've created a boilerplate in gulp that might seem useful for you. Gulp 4 has some major changes to the syntax and that might be the reason that's throwing you errors.
Check out https://github.com/abhijithvijayan/gulp-sass-bootstrap-boilerplate
I hope it helps.
Almost 2 years later, but you're right to question if there are better ways. Gulp is has historically been a file watcher, task runner & accompanying ecosystem with many tasks that based around file-level manipulations.
Gulp has seen lots of extension over the years, but best practices have moved on to bundlers like webpack or parcel to link their JS code. This linking process includes things like tree shaking and minification of the final output. This is all thanks to the bundlers taking more of a semantic interest in your code thanks to the various types of JS module systems (es, nodejs).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.