Skip to content

Commit

Permalink
build(bin): setup binary build (to production) script
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Jul 5, 2019
1 parent f3285ff commit bafbcbd
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions build/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node

'use strict'

process.env.NODE_ENV = 'production'

// Node.js modules
const path = require('path')

// build bundle with Webpack
const webpack = require('webpack')
const webpackConfig = require(path.join(process.cwd(), 'webpack.config'))

// additional Webpack plugins
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
if (!webpackConfig.plugins) {
webpackConfig.plugins = []
}
webpackConfig.plugins.push(
new CleanWebpackPlugin()
)

const fatalError = err => {
if (err) {
console.error(err)
}
// exit with failure
process.exit(1)
}

webpack(webpackConfig, (err, stats) => {
// console.log(stats)
if (err) {
fatalError(err)
}

// check and handle webpack errors and warnings
const info = stats.toJson()
if (stats.hasErrors()) {
let err = info.errors
fatalError(err)
}
if (stats.hasWarnings()) {
console.warn(info.warnings)
}
})

0 comments on commit bafbcbd

Please sign in to comment.