Last active
May 15, 2020 10:03
-
-
Save farooqarahim/6b77d1dc40b01ed8f33873944d80c307 to your computer and use it in GitHub Desktop.
Gulp 4, Browserify transform for Babel & Watchify
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
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