node.js - Automate this browserify command whenever js file is changed -


whenever change function.js, have manually run command below browserify function.js bundle.js

$ browserify function.js --standalone function > bundle.js 

how can step automated such command run automatically in background whenever function.js modified?

i using node.js v6.9 webstorm 2016.2 on windows 10.

the browserify command want run is;

$ browserify function.js --standalone function > bundle.js 

taking reference https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md

here full code need. slight modification reference code needed opts browserify.

'use strict';  var watchify = require('watchify'); var browserify = require('browserify'); var gulp = require('gulp'); var source = require('vinyl-source-stream'); var buffer = require('vinyl-buffer'); var gutil = require('gulp-util'); var sourcemaps = require('gulp-sourcemaps'); var assign = require('lodash.assign');  // add custom browserify options here var customopts = {   entries: ['./function.js'],   standalone: 'function', }; var opts = assign({}, watchify.args, customopts); var b = watchify(browserify(opts));   // add transformations here // i.e. b.transform(coffeeify);  gulp.task('js', bundle); // can run `gulp js` build file b.on('update', bundle); // on dep update, runs bundler b.on('log', gutil.log); // output build logs terminal  function bundle() {   return b.bundle()     // log errors if happen     .on('error', gutil.log.bind(gutil, 'browserify error'))     .pipe(source('bundle.js'))     // optional, remove if don't need buffer file contents     .pipe(buffer())     // optional, remove if dont want sourcemaps     .pipe(sourcemaps.init({loadmaps: true})) // loads map browserify file        // add transformation tasks pipeline here.     .pipe(sourcemaps.write('./')) // writes .map file     .pipe(gulp.dest('./dist')); } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -