Skip to content

Instantly share code, notes, and snippets.

@mikaelbr
Forked from Sigmus/gulpfile.js
Last active February 8, 2021 00:32
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mikaelbr/54b02412fc651d4e5c9a to your computer and use it in GitHub Desktop.
Save mikaelbr/54b02412fc651d4e5c9a to your computer and use it in GitHub Desktop.
Gulp + Browserify + Reactify + OS Notification
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var reactify = require('reactify');
var watchify = require('watchify');
var notify = require("gulp-notify");
var scriptsDir = './scripts';
var buildDir = './build';
// Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/
function buildScript(file, watch) {
var props = watchify.args;
props.entries = [scriptsDir + '/' + file];
props.debug = true;
var bundler = watch ? watchify(browserify(props)) : browserify(props);
bundler.transform(reactify);
function rebundle() {
var stream = bundler.bundle();
return stream.on('error', notify.onError({
title: "Compile Error",
message: "<%= error.message %>"
}))
.pipe(source(file))
.pipe(gulp.dest(buildDir + '/'));
}
bundler.on('update', function() {
rebundle();
gutil.log('Rebundle...');
});
return rebundle();
}
gulp.task('build', function() {
return buildScript('main.js', false);
});
gulp.task('default', ['build'], function() {
return buildScript('main.js', true);
});
{
"name": "scripts",
"version": "0.0.0",
"description": "",
"main": "gulpfile.js",
"devDependencies": {
"browserify": "^6.0.0",
"gulp": "^3.8.7",
"gulp-notify": "^2.0.1",
"gulp-util": "^3.0.1",
"reactify": "^0.14.0",
"uglify-js": "^2.4.13",
"vinyl-source-stream": "^1.0.0",
"watchify": "^2.0.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause"
}
@cloud-walker
Copy link

What about error line and column?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment