Created
December 30, 2018 21:10
-
-
Save notiv-nt/ca531c6d675d227e1bdf82e74864b76b to your computer and use it in GitHub Desktop.
Gulp javascript task — browserify version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let PRODUCTION_MODE = process.argv.indexOf('--minify') !== -1; | |
const gulp = require('gulp'); | |
const _ = require('gulp-load-plugins')(); | |
const fs = require('fs'); | |
gulp.task('javascript', () => { | |
const browserify = require('browserify'); | |
const tasks = ['./source/js/index.js', 'source/js/sw.js'] | |
.map(entry => { | |
if (!fs.existsSync(entry)) { | |
return; | |
} | |
return browserify({ entries: entry, debug: !PRODUCTION_MODE }) | |
.transform(require('babelify'), { | |
presets: ['@babel/preset-env'], | |
sourceMaps: !PRODUCTION_MODE, | |
}) | |
.bundle() | |
// Optional | |
// .on('error', _.errorNotifier.notify) | |
// .pipe(_.errorNotifier()) | |
.pipe(require('vinyl-source-stream')(entry)) | |
.pipe(require('vinyl-buffer')()) | |
.pipe( | |
_.rename({ | |
dirname: '', | |
}) | |
) | |
.pipe(_.if(PRODUCTION_MODE, _.streamify(_.terser()))) | |
.pipe(gulp.dest('./public/assets/js')) | |
}) | |
.filter(task => task); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"build": "gulp javascript --minify" | |
}, | |
"dependencies": { | |
"@babel/core": "7.2.2", | |
"@babel/preset-env": "7.2.0", | |
"babelify": "10.0.0", | |
"browserify": "16.2.3", | |
"gulp": "^3.9.1", | |
"gulp-if": "^2.0.2", | |
"gulp-load-plugins": "^1.5.0", | |
"gulp-rename": "1.4.0", | |
"gulp-streamify": "1.0.2", | |
"gulp-terser": "^1.1.6", | |
"vinyl-buffer": "1.0.1", | |
"vinyl-source-stream": "2.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment