Last active
May 7, 2020 07:47
-
-
Save devyfriend/aa18ff8d3d34e7248fdeb6ef0b9a2e4f to your computer and use it in GitHub Desktop.
gulp browserify babelify
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 spawn = require("child_process").spawn; | |
const gulp = require( 'gulp' ); | |
const babel = require( 'gulp-babel' ); | |
const babelify = require("babelify"); | |
const browserify = require("browserify"); | |
const source = require( "vinyl-source-stream" ); | |
const buffer = require( 'vinyl-buffer' ); | |
const uglify = require( 'gulp-uglify' ); | |
function reload () | |
{ | |
var p; | |
gulp.watch("gulpfile.js", spawnChildren); | |
var spawnChildren = function(callback) { | |
if (p) p.kill(); | |
p = spawn( "gulp", ["default"], { stdio: "inherit" }); | |
if (callback) callback(); | |
}(); | |
} | |
function js(){ | |
return browserify("./app.js") | |
.transform(babelify) | |
.bundle() | |
.pipe(source("app.js")) | |
.pipe(buffer()) | |
.pipe(babel()) | |
.pipe(uglify({ mangle: { toplevel: true } })) | |
.pipe(gulp.dest("./dist")); | |
} | |
gulp.watch( [ './app.js', './src/*.js' ], js ); | |
gulp.watch( [ "./gulpfile.js"], reload); | |
exports.default = js; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment