Skip to content

Commit

Permalink
added browserify script #494
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin committed Sep 6, 2017
1 parent a9d7219 commit 31f5fc6
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
"scripts": {
"test": "grunt test lint",
"start": "node ./bin/www",
"preinstall": "node version-check.js"
"preinstall": "node version-check.js",
"build-js": "node ./tasks/build-js"
},
"devDependencies": {
"autoprefixer": "7.1.1",
"babel-polyfill": "6.16.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babelify": "^7.3.0",
"bluebird": "3.4.6",
"browserify": "^14.4.0",
"buster": "0.7.12",
"chromedriver": "2.25.1",
"express": "4.15.2",
Expand Down Expand Up @@ -55,6 +60,7 @@
"selenium-server-standalone-jar": "3.0.1",
"stylefmt": "^6.0.0",
"stylelint": "^8.0.0",
"watchify": "^3.9.0",
"worldview-components": "1.3.3"
}
}
78 changes: 78 additions & 0 deletions tasks/build-js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node
// template from https://github.com/petesaia/node-native-task-runner/blob/master/bin/build-js

//const UglifyJS = require('uglify-js');
const fs = require('fs');
const browserify = require('browserify');
const watchify = require('watchify');

const entry = 'wv.main.js';
const output = './build/js.js';
const outputMin = './build/js.mins.js';

// override, should set this from an argument: --dev or --prod
// and default to dev
process.env.NODE_ENV = 'development';

const b = browserify(entry, {
debug: true,
sourceMaps: true,
cache: {},
packageCache: {},
plugin: [process.env.NODE_ENV !== 'production' ? watchify : null],
basedir: './web/js'
})
.transform('babelify', {
plugins: [ ],
presets: [
'es2015',
'react'
]
});

function bundle() {
const stream = fs.createWriteStream(output);

const onComplete = (function() {
const begin = Date.now();

return function() {
console.log('Build complete in ' + (Date.now() - begin) / 1000 + 'secs');
};
})();

b.bundle()
.on('error', function(err) {
console.error(err);
this.emit('end');
})
.pipe(stream)

stream.on('finish', function() {
if (process.env.NODE_ENV === 'production') {
// console.log('Complete, now compressing because production.');

// const minified = UglifyJS.minify(fs.readFileSync(output, 'utf8'), {
// // warnings: true,
// compress: {
// dead_code: true
// }
// });

// if (minified.error) {
// return console.error('UGLIFY Error:', minified.error);
// }

// fs.writeFileSync(outputMin, minified.code);
// onComplete();

} else {
console.log('All done! (dev mode - not compressing)');
onComplete();
}
});
}

bundle();

b.on('update', bundle);

0 comments on commit 31f5fc6

Please sign in to comment.