Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var browserify = require('browserify');
- var watchify = require('watchify');
- var bs = require('browser-sync');
- var ws = require('fs').createWriteStream;
- var to5ify = require('6to5ify');
- var outDir = './public/';
- var config = {
- browserify: {
- entryFile: './src/index.js',
- outFile: outDir + 'bundle.js',
- args: {
- cache: {}, //
- packageCache: {}, // these three are required for watchify
- fullPaths: true, //
- debug: true
- }
- },
- browserSync: {
- server: {
- baseDir: outDir
- }
- }
- };
- var tasks = {
- watch: function() {
- var b = browserify(config.browserify.args)
- .transform(to5ify.configure({
- experimental: true,
- modules: 'commonInterop'
- }))
- .add('6to5/polyfill')
- .require(config.browserify.entryFile, { entry: true });
- var w = watchify(b);
- var rebundle = function() {
- w.bundle()
- .on('error', function(err) {
- var msg = '[Browserify] ERROR: ' + err.message;
- if(bs.active) {
- // set a timeout, because the initial 'BrowserSync connected'
- // message helpfully squashes any other notifications on reload
- setTimeout(function() {
- bs.notify(msg, 10000);
- }, 1000);
- }
- console.error(msg);
- })
- .on('end', function() {
- if(bs.active) {
- bs.reload();
- }
- })
- .pipe(ws(config.browserify.outFile));
- };
- w.on('update', rebundle);
- w.on('log', console.log);
- rebundle();
- },
- serve: function() {
- bs(config.browserSync);
- tasks.watch();
- }
- };
- var task = process.argv.slice(2)[0];
- tasks[task]();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement