Minified js (#485)

no issue

- Added a `js` task to run on the gulp build process and minifies our js files
- Changed the required scripts in `default.hbs` to use the minified js files in `/built/`
- Moved existing `js` tasks from `zip` task
This commit is contained in:
Aileen Nowak
2018-10-12 12:41:06 +07:00
committed by John O'Nolan
parent 5ad6e1ed1f
commit bef56a2294
8 changed files with 28 additions and 11 deletions

View File

@ -26,10 +26,12 @@ var nodemonServerInit = function () {
livereload.listen(1234);
};
gulp.task('build', ['css'], function (/* cb */) {
gulp.task('build', ['css', 'js'], function (/* cb */) {
return nodemonServerInit();
});
gulp.task('generate', ['css', 'js']);
gulp.task('css', function () {
var processors = [
easyimport,
@ -48,25 +50,34 @@ gulp.task('css', function () {
.pipe(livereload());
});
gulp.task('js', function () {
var jsFilter = filter(['**/*.js'], {restore: true});
return gulp.src('assets/js/*.js')
.on('error', swallowError)
.pipe(sourcemaps.init())
.pipe(jsFilter)
.pipe(uglify())
.pipe(jsFilter.restore)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/built/'))
.pipe(livereload());
});
gulp.task('watch', function () {
gulp.watch('assets/css/**', ['css']);
});
gulp.task('zip', ['css'], function () {
gulp.task('zip', ['css', 'js'], function () {
var targetDir = 'dist/';
var themeName = require('./package.json').name;
var filename = themeName + '.zip';
var jsFilter = filter(['**/*.js'], {restore: true});
return gulp.src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**'
])
.pipe(jsFilter)
.pipe(uglify())
.pipe(jsFilter.restore)
.pipe(zip(filename))
.pipe(gulp.dest(targetDir));
});