-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benjamin
committed
Sep 6, 2017
1 parent
a9d7219
commit 31f5fc6
Showing
2 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |