Skip to content

Instantly share code, notes, and snippets.

@farooqarahim
Last active May 15, 2020 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farooqarahim/6b77d1dc40b01ed8f33873944d80c307 to your computer and use it in GitHub Desktop.
Save farooqarahim/6b77d1dc40b01ed8f33873944d80c307 to your computer and use it in GitHub Desktop.
Gulp 4, Browserify transform for Babel & Watchify
const { watch, dest, series, parallel } = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const terser = require('gulp-terser-js');
const browserify = require('browserify');
const watchify = require('watchify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
function Task() {
return watchify(
browserify({
entries: [`./lib/index.js`],
transform: [
babelify.configure({ presets: ['@babel/preset-env'], plugins: ['@babel/plugin-transform-runtime', '@babel/plugin-transform-async-to-generator'] }),
],
standalone: 'std-test',
debug: true,
})
)
.bundle()
.on('error', function(error) { console.error(error); this.emit('end'); })
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(terser())
.pipe(sourcemaps.write('.'))
.pipe(dest('dist'));
}
function watchTask() {
watch(['lib/**/*.js'], parallel(Task));
}
exports.default = series(clean, parallel(Task), watchTask);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment