Exemple #1
0
gulp.task('js', () => {
  var bundler = browserify({
    cache: {},
    debug: global.isWatching,
    entries: [`./${pkg.folders.src}/js/main.js`],
    fullPaths: false,
    packageCache: {}
  }).transform(babelify.configure({
    presets: ['es2015']
  }))

  var bundle = () => {
    bundler
      .bundle()
      .pipe(source('main.js'))
      .pipe(buffer())
      .pipe(global.isWatching ? util.noop() : uglify())
      .pipe(gulp.dest(`./${pkg.folders.dist}/js`))
  }

  if (global.isWatching) {
    bundler = watchify(bundler)
    bundler.on('update', bundle)
  }

  return bundle()
})
gulp.task('browserify' , () =>{


	var bundler = browserify({
		cache:{},
		packageCache:{},
		fullPaths:true,
		entries:['./src/client/js/index.js'],
		extensions:['.js'],
		debug:true
	}).transform(babelify.configure({presets: ["es2015"]}))

	let bundle = ()=>{
		return bundler.bundle()
		.on('error' , (err) => { console.log('err: ' , err);})
		.pipe(source('index.js'))
    	.pipe(buffer())	
    	//.pipe(uglify())
		.pipe(gulp.dest('./public/js/'))
		.on('end' , ()=>{})
	};

	return bundle();

})
function createBundler(src) {
  var b;

  if (plugins.util.env.production) {
    b = browserify();
  }
  else {
    b = browserify({
      cache: {}, packageCache: {}, fullPaths: true,
      debug: true
    });
  }

  b.transform(babelify.configure({
    stage: 1
  }));

  if (plugins.util.env.production) {
    b.transform({
      global: true
    }, 'uglifyify');
  }

  b.add(src);
  return b;
}
Exemple #4
0
function buildScript(file, watch) {
    var props = extend({}, watchify.args, {
        entries: [srcDir + 'js/' + file],
        debug: true,
        extensions: ['.js', '.jsx']
    });

    var bblfy = babelify.configure({
        only: /(src\/js)/,
        optional: ['runtime']
    });

    var brwsfy = browserify(props).transform(bblfy);

    var bundler = watch ? watchify(brwsfy, {
        ignoreWatch: true
    }) : brwsfy;

    function rebundle() {
        return bundler.bundle()
            .on('error', handleError)
            .pipe(source(jsTargetName))
            .pipe(buffer())
            .pipe($.sourcemaps.init({ loadMaps: true }))
            .pipe($.sourcemaps.write(mapsDir))
            .pipe(gulp.dest(buildDir));
    }

    bundler.on('update', rebundle);
    bundler.on('log', $.util.log);
    bundler.on('error', $.util.log);
    return rebundle();
}
function buildScript(file, watch) {
  var props = {
    entries: ['./src/js/' + file],
    debug: true,
    transform: [babelify.configure({ presets: ['es2015', 'react'] })]
  };

  var bundler = watch ? watchify(browserify(props), { poll: true }) :
    browserify(props);

  function rebundle() {
    var stream = bundler.bundle();
    return stream
      .on('error', handleErrors)
      .pipe(source(file))
      // .pipe(buffer())
      // .pipe(uglify())
      // .pipe(rename('app.min.js'))
      .pipe(gulp.dest('./build/js/'))
      .pipe(reload({ stream: true }));
  }

  // Listen for an update and run rebundle
  bundler.on('update', function() {
    rebundle();
    gutil.log('Rebundle...');
  });

  // Run it once the first time buildScript is called
  return rebundle();
}
Exemple #6
0
gulp.task('default', function () {
    var bundler = watchify(browserify({
        entries: [
            './app/public/javascripts/components/main-page/main-page.js'
            // './app/public/javascripts/components/navbar/navbar.js'
        ],
        // transform: [reactify],
        extensions: ['.js', '.jsx'],
        debug: true,
        cache: {},
        packageCache: {},
        fullPaths: true
    }).transform(babel.configure({presets: ["es2015", "react"],
        plugins: [
            "transform-es2015-modules-commonjs",
            "transform-react-jsx",
            "transform-es2015-arrow-functions"
    ]})));

    function build(file) {
        if (file) gutil.log('Recompiling ' + file);
        return bundler
            .bundle()
            .on('error', gutil.log.bind(gutil, 'Browserify Error'))
            .pipe(source('app/public/javascripts/build/application.js'))
            .pipe(buffer())
            .pipe(sourcemaps.init({ loadMaps: true }))
            .pipe(sourcemaps.write('./'))
            .pipe(gulp.dest('./'));
    }

    build();
    bundler.on('update', build);
});
Exemple #7
0
        .pipe($.tap((file) => {
            file.contents = browserify(file.path, {debug: true})
                .transform(babelify.configure(project.babel))
                .bundle();

            $.util.log(`browserify: ${$.util.colors['green']('✔')} ${file.relative}`);
        }))
Exemple #8
0
function buildScript(file, watch) { 
	var props = { 
		entries : ['./components/' + file], 
		debug : true, 
		transform : babelify.configure({ 
			presets: ['react', 'es2015'] 
		}) 
}; 

//watchify if watch set to true. otherwise browserify once 
var bundler = watch ? watchify(browserify(props)) : browserify(props); 
function rebundle(){ 
	var stream = bundler.bundle(); 
	return stream 
		.on('error', handleErrors) 
		.pipe(source('bundle.js')) 
		.pipe(gulp.dest('./build/')); 
	} 
		bundler.on('update', function() { 
		var updateStart = Date.now(); 
		rebundle(); 
	console.log('Updated!', (Date.now() - updateStart) + 'ms'); 
	}) 

	// run it once the first time buildScript is called 
	return rebundle(); 
	} 
Exemple #9
0
var bundle = function bundle(watch) {

    //Set up browserify, to run on JS and JSX files, including watchify plugin to rerun when files change
    var b = watchify(browserify('app/js/app.jsx',
        {
            entries     : 'app/js/app.jsx',
            extensions  : ['.jsx'],
            cache       : {},
            packageCache: {},
        }).
        transform(babelify.configure({
            presets: ["es2015", "react"]
        })), { poll: true});

    var doBundling = function doBundling() {
        b.bundle().on('error', function(error){
            if (error instanceof SyntaxError) {
                gutil.log(gutil.colors.red('Syntax Error:'));
                gutil.log(gutil.colors.red(error.message));
                gutil.log(gutil.colors.red(error.codeFrame));
            } else {
                gutil.log(gutil.colors.red('Error:', error.message));
            }
        }).pipe(source('app.js')).pipe(gulp.dest('dist/js'));
        gutil.log('Bundling complete');
    };

    //If in watch mode trigger a rebundle on file changes:
    if(watch) {
        b.on('update', doBundling);
        gutil.log('Watchify watching for JS and JSX updates...');
    }

    return doBundling();
};
/**
 * Process JS with babel + browserify
 * @param deferred
 * @param previous
 * @param ctx
 */
function processJS (deferred, previous, ctx) {

    var input  = ctx.path.make('babel-browserify', 'input');
    var root   = ctx.path.make('babel-browserify', 'root');
    var output = ctx.path.make('babel-browserify', 'output');
    var map    = output + '.map';

    ctx.mkdirp.sync(dirname(output));

    browserify(input, { debug: true })
        .transform(babelify.configure({
            sourceMapRelative: root
        }))
        .bundle()
        .on('error', function (err) {
            deferred.notify({level: 'error', msg: [
                [
                    '{err: } from {yellow:babel-browserify} task:',
                    '%s',
                    err.codeFrame
                ].join('\n'),
                err.message
            ]});
            err.crossbow_silent = true;
            deferred.reject(err);
        })
        .pipe(exorcist(map))
        .pipe(fs.createWriteStream(output))
        .on('close', deferred.resolve)
}
Exemple #11
0
module.exports = function(options) {

  options = options && typeof options == 'object' ? options : {};

  var viewEngines = options.viewEngines || [];
  var cssExts = options.cssExtnames;
  var jsExts = options.jsEXNames;
  var filecopyConfig = options.filecopy;
  var cssTransform = options.cssTransform;
  var autoprefixer = options.autoprefixer;
  var babel = options.babel;

  // remove ['.js'].concat() someday when uglify-js upgraded for new browsers, if possible, we DO NOT transpile!
  // ['.js'].concat() is important or babelify will not transform ext === '.js'
  var jsx = babelify.configure(Object.assign({ extensions: ['.js'].concat(jsExts) }, babel));

  return function (file) {

    var ext = extname(file);
    if (ext == '.ract') return ractive(options);
    if (~viewEngines.indexOf(ext) != 0) return htmlview(options);
    if (~cssExts.indexOf(ext) != 0) return styles({ file: file, cssTransform: cssTransform, autoprefixer: autoprefixer });

    // remove ext == '.js' someday when uglify-js upgraded for new browsers, if possible, we DO NOT transpile!
    if (~jsExts.indexOf(ext) != 0 || ext == '.js') return jsx(file);
    if (~filecopyConfig.moveExtnames.indexOf(ext) != 0) return filecopy(file, filecopyConfig);

    return through();
  };
};
Exemple #12
0
gulp.task('js', function() {
  browserify({entries: './src/app.js', extensions: ['.jsx','.js']})
  .transform(babelify.configure({stage: 0}))
  .bundle()
  .pipe(source('app.js'))
  .pipe(gulp.dest('./build/js/'))
})
Exemple #13
0
gulp.task('watchify', function() {
  gulp.watch(paths.HTML, ['copy:HTML']);
  gulp.watch(paths.CSS, ['copy:CSS']);
  gulp.watch(paths.JS, ['copy:SERVER', 'server']);
  gulp.watch(paths.ROUTES, ['copy:ROUTES', 'server']);

  var watcher = watchify( browserify({
    entries: [paths.APP_WATCH_POINT],
    debug: true,
    cache: {}, packageCache: {}, fullPaths: true
  }))
    .transform(babelify.configure({
      experimental: true
    }));

  function rebundle() {
    return watcher.bundle()
      .on('error', notify.onError())
      .pipe( source( paths.BUNDLE ) )
      .pipe( gulp.dest( paths.BUNDLE_DEST ) )
      .on('end', function() {
        gulp.start(['server']);
      });
  }

  watcher.on('update', rebundle);

  return rebundle();
});
gulp.task('dev-scripts', ['jshint'], function() {

	var sources = browserify({
		entries: src.scripts.app,
		debug: true // Build source maps
	})
		.transform(babelify.configure({
			// You can configure babel here!
			// https://babeljs.io/docs/usage/options/
		}));

	return sources.bundle()
		.pipe(vinylSourceStream(out.scripts.file))
		.pipe(vinylBuffer())
		.pipe(plugins.sourcemaps.init({
			loadMaps: true // Load the sourcemaps browserify already generated
		}))
		.pipe(plugins.ngAnnotate())
		.pipe(plugins.sourcemaps.write('./', {
			includeContent: true
		}))
		.pipe(gulp.dest(out.scripts.folder))
		.pipe(plugins.connect.reload());

});
gulp.task('js', ['lint', 'file-system'], function () {
  gulp.src(path.js.lib.entry, { read: false })
    .pipe(plumber())
    .pipe(browserify({
      debug: !production,
      transform: babelify.configure({
        ignore: /babel/,
      })
    }))
    .on('prebundle', function (bundle) {
      bundle.require('./fs', { expose: 'zsh.js/fs' });
      bundle.require('./zsh', { expose: 'zsh.js' });
      bundle.require('./args-parser', { expose: 'zsh.js/args-parser' });
      bundle.require('./command-manager', { expose: 'zsh.js/command-manager' });
      bundle.require('./console', { expose: 'zsh.js/console' });
      bundle.require('./file', { expose: 'zsh.js/file' });
      bundle.require('./stream', { expose: 'zsh.js/stream' });
    })
    .pipe(rename('zsh.js'))
    .pipe(gulp.dest(path.build))
    .pipe(rename('zsh.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest(path.build))
    .pipe(refresh(server));
});
Exemple #16
0
gulp.task('babel', function () {
  return browserify({
    entries: config.scripts.babel.main,
    debug: true
  })
  .transform(babelify.configure({
    resolveModuleSource: function (relativeSourcePath) {
      var parts = relativeSourcePath.split('/');
      var file  = parts.pop();
      var first = parts.shift();
      var path  = parts.join('/');

      path = (path.length ? path + '/' : '');

      if (!first) {
        first = file;
      }

      return require('path').join(__dirname, config.scripts.babel.src, first, path, file);
    }
  }))
  .bundle()
  .pipe(source('main.min.js'))
  .pipe(gulp.dest(config.scripts.dest));
});
Exemple #17
0
/*
 * JS
 */

 // the compileJS() does the actual JS compilation
function compileJS(watch) {

  var bundler = watchify(browserify(paths.srcAssets + 'js/main.js', {
    debug: true,
    extensions: ['js']
  }).transform(babelify.configure({
      presets: ["es2015"]
    }))
  );

  function rebundle() {
    bundler.bundle()
      .on('error', function(err) {
        console.error(err);
        this.emit('end'); }
      )
      .pipe(source('main.js'))
      .pipe(buffer())
      .pipe(sourcemaps.init({ loadMaps: true }))
      .pipe(sourcemaps.write('./'))
      .pipe(gulp.dest(paths.devAssets + 'js'))
      .pipe(notify({message: 'JS compiled!', onLast: true}))
  }

  // if the watch parameter is passed a true argument, then activate watching
  if (watch) {
    bundler.on('update', function() {
      console.log('-> bundling...');
      rebundle();
    });
  }

  rebundle();
}
Exemple #18
0
function buildScript(file) {
  var bundler = browserify(customOpts);
  if (!global.isProd) {
    bundler = watchify(bundler);
    bundler.on('update', rebundle);
  }
  bundler.transform(babelify.configure({
    extensions: ['.es6']
  }));
  bundler.transform(ngAnnotate);
  bundler.transform(partialify);
  bundler.transform('brfs');

  function rebundle() {
    var stream = bundler.bundle();
    var sourcemapsRequired = global.isProd && config.browserify.sourcemap;
    gutil.log('Rebundle...');
    return stream.on('error', handleErrors)
      .pipe(source(file))
      .pipe(gulpif(sourcemapsRequired, buffer()))
      .pipe(gulpif(sourcemapsRequired, sourcemaps.init({loadMaps: true})))
      .pipe(gulpif(global.isProd, streamify(uglify({
        compress: {drop_console: false},
        beautify : false,
        mangle   : true
      }))))
      .pipe(gulpif(sourcemapsRequired, sourcemaps.write()))
      .pipe(gulp.dest(config.scripts.dest))
      .pipe(gulpif(!global.isProd, livereload()));
  }

  return rebundle();
}
Exemple #19
0
function createBundle(src) {
  var customOpts = {
    entries: [src],
    debug: true
  };
  var opts = assign({}, watchify.args, customOpts);
  var b;

  // this is a quick hack. Figure out what's really happening
  if (plugins.util.env.production) {
    b = browserify(opts);
  }
  else {
    b = watchify(browserify(opts));
  }

  b.transform(babelify.configure({
    stage: 1
  }));

  if (plugins.util.env.production) {
    b.transform({
      global: true
    }, 'uglifyify');
  }

  b.on('log', plugins.util.log);
  return b;
}
gulp.task('build:client', function () {
  const isProduction = process.env.NODE_ENV === 'production';
  const browserifyOptions = {
    entries: ['./src'],
    debug: true,
    fullPaths: false
  };
  const babelifyOptions = {
    presets: ['es2015', 'react'],
    plugins: ['babel-plugin-transform-object-rest-spread']
  };
  const stream = browserify(browserifyOptions)
    .transform(envify())
    .transform(babelify.configure(babelifyOptions));

  vendors.forEach(function (vendor) {
    stream.external(vendor);
  });

  return stream.bundle()
    .pipe(source('application.js'))
    .pipe(buffer())
    .pipe(gulpif(!isProduction, sourcemaps.init({ loadMaps: true })))
      .pipe(gulpif(isProduction, uglify()))
    .pipe(gulpif(!isProduction, sourcemaps.write('.')))
    .pipe(gulp.dest(config.build.javascripts));
});
Exemple #21
0
function compileJS(watch) {
	const bundler = watchify(browserify({
			entries: [`${FILE_DIR}/${fileName}`],
			debug: true,
			extensions: [' ', 'js', 'jsx']
		}).transform(babel.configure({
			presets: babelPresets
		}))
	);

	function rebundle() {
		bundler.bundle()
			.on('error', (err)=> { console.error(err); this.emit('end'); })
			.pipe(source(fileName))
			.pipe(buffer())
			.pipe(sourcemaps.init({ loadMaps: true }))
			.pipe(sourcemaps.write('./'))
			.pipe(gulp.dest(BUILD_DIR));
	}

	if (watch) {
		bundler.on('update', function() {
			console.log(`-> Bundling ${BUILD_DIR}...`);
			rebundle();
		});
	}

	rebundle();
}
Exemple #22
0
function createBundler(watch) {
    var bundler = browserify(extend({
        debug: true,
        entry: true
    }, watch ? watchify.args : { }));
    
    if(watch) {
        bundler = watchify(bundler);
    }

    glob.sync(config.test.files).forEach(function(filePath) {
        bundler = bundler.add(filePath);
    });

    bundler = bundler
    .transform(brfs)
    .transform(babelify.configure({
        only: /^(?!.*node_modules)+.+\.js$/,
        sourceMap: 'inline',
        sourceMapRelative: __dirname
    }));
    
    if(watch) {
        bundler = bundler.on('update', watch);
    }

    return bundler;
}
Exemple #23
0
gulp.task('watchify', function() {
  watchify.args.debug = true;
  var bundler = watchify(
    browserify('client/index.js', watchify.args)
      .transform(babelify.configure({
        presets: ['es2015']
      }))
  );

  bundler.on('update', rebundle);
  bundler.on('log', gutil.log.bind(gutil));

  function rebundle() {
    return bundler.bundle()
      .on('error', gutil.log)
      .pipe(source('bundle.js'))
      .pipe(buffer())
      .pipe(sourcemaps.init({loadMaps: true}))
        .pipe(ngAnnotate({single_quotes: true}))
        .pipe(uglify())
      .pipe(sourcemaps.write('client/'))
      .pipe(gulp.dest(BUILD))
      .pipe(browserSync.reload({stream:true}));
  }

  return rebundle();
});
gulp.task('js', function() {
	const babelifyTransform = babelify.configure({
		presets: ['env']
	});

	glob(opt.js.src, function(err, files) {
		files.map(function(entry) {
			return browserify({
				entries: entry,
				debug: true,
				transform: [babelifyTransform]
			}).bundle()
				.on('error', handle.genericReporter)
				.pipe(plumber({errorHandler: handle.genericReporter}))
				.pipe(source(path.basename(entry).replace(/\.js$/, '.min.js')))
				.pipe(buffer())
				.pipe(jshint({
					esnext: true
				}))
				.pipe(uglify())
				.pipe(handle.notify('JS compiled - <%= file.relative %>'))
				.pipe(handle.pipeLog('compiled'))
				.pipe(gulp.dest(opt.js.dest));
		})
	});
});
Exemple #25
0
gulp.task('buildScripts', function() {
    return browserify(sourceFile)
      .transform(babelify.configure({ plugins: ['object-assign'] }))
      .bundle()
      .pipe(source(destFileName))
      .pipe(gulp.dest('dist/scripts'));
});
Exemple #26
0
    var rebundle = function () {
        b.transform(babelify.configure({
            presets: ["es2015", "react"],
            plugins:["transform-decorators-legacy"]


})
                   );

    if(isProduction){
        b.plugin('minifyify', {
        map: 'main.map',
        uglify: {
        mangle: true,
        compress: {
        drop_debugger: true,
        drop_console: true,
        }
        },
        output: DIST_DIR + '/build/main.min.map'
        })
    };
            b.external(vendor_libs)
            .add(SRC_DIR + "/appBase.js")
            .bundle()
            .on("error", function (err) { map_error(err) })
            .pipe(source('main.min.js'))
            .pipe(gulp.dest(DIST_DIR + "/build"));
    }
function buildScript(file, watch) {
  var props = {
    entries: ['./scripts/' + file],
    debug : true,
    cache: {},
    packageCache: {},
    transform:  [babelify.configure({stage : 0 })]
  };

  // watchify() if watch requested, otherwise run browserify() once
  var bundler = watch ? watchify(browserify(props)) : browserify(props);

  function rebundle() {
    var stream = bundler.bundle();
    return stream
      .on('error', handleErrors)
      .pipe(source(file))
      .pipe(gulp.dest('./build/'))
      // If you also want to uglify it
      // .pipe(buffer())
      // .pipe(uglify())
      // .pipe(rename('app.min.js'))
      // .pipe(gulp.dest('./build'))
      .pipe(reload({stream:true}))
  }

  // listen for an update and run rebundle
  bundler.on('update', function() {
    rebundle();
    gutil.log('Rebundle...');
  });

  // run it once the first time buildScript is called
  return rebundle();
}
Exemple #28
0
function scripts() {
  var bundler = browserify({
    entries: ['./client/components/app.jsx'],
    transform: babelify.configure({ presets: ['react', 'es2015'] }),
    debug: false,
    cache: {},
    packageCache: {},
    fullPaths: false
  });
  var watcher = watchify(bundler);

  return watcher
    .on('update', function() {
      var updateStart = Date.now();
      console.log('Updating!');
      watcher.bundle()
      .on('error', function(err) {
        console.log('Error with compiling components', err.message);
      })
      .pipe(source('bundle.js'))
      .pipe(buffer())
      .pipe(uglify())
      .pipe(gulp.dest('./client/build/'));
      console.log('Updated!', (Date.now() - updateStart) + 'ms');
    })
    // Create the initial bundle when starting the task
    .bundle()
    .on('error', function(err) {
      console.log('Error with compiling components', err.message);
    })
    .pipe(source('bundle.js'))
    .pipe(buffer())
    .pipe(uglify())
    .pipe(gulp.dest('./client/build/'));
}
gulp.task('bundle-lib', function bundleLib() {
    var stream = browserify(Object.assign({}, browserifyOptions, {
            entries: PATHS.ADMIN_JAVASCRIPT_SRC + '/bundles/lib.js'
        }))
        .transform(babelify.configure({
            presets: ['es2015'],
            ignore: /(thirdparty)/,
            comments: false
        }))
        .on('log', function (msg) { gulpUtil.log('Finished bundle-lib.js ' + msg); })
        .on('update', bundleLib)
        .require(PATHS.FRAMEWORK_JAVASCRIPT_SRC + '/jQuery.js', { expose: 'jQuery' })
        .require(PATHS.FRAMEWORK_JAVASCRIPT_SRC + '/i18n.js', { expose: 'i18n' })
        .bundle()
        .on('error', notify.onError({
            message: 'Error: <%= error.message %>',
        }))
        .pipe(source('bundle-lib.js'))
        .pipe(buffer());

    if (!isDev) {
        stream.pipe(uglify());
    }

    return stream.pipe(gulp.dest(PATHS.ADMIN_JAVASCRIPT_DIST));
});
function buildScripts(file,watch){
	var props = {
		entries: ['./scripts/'+file],
		cache: {},
		packageCache: {},
		transform: [babelify.configure({presets: ["es2015", "react"]})]
	};

	var bundler = watch ? watchify(browserify(props)) : browserify(props);

	function rebundle(){
		var stream = bundler.bundle();
		return stream
			.on('error', handleErrors)
			.pipe(source(file))
			.pipe(gulp.dest('./build/'))
			.pipe(reload({stream: true}))
	};

	bundler.on('update', function(){
		rebundle();
		gutil.log('Rebundle...');
	})

	return rebundle();
};