-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.js
63 lines (56 loc) · 1.53 KB
/
webpack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var webpack = require("webpack")
var webpackSourceMapSupport = require("webpack-source-map-support")
var nodeExternals = require("webpack-node-externals")
var PROD = ( process.env.NODE_ENV === 'production' )
var plugins = [
new webpackSourceMapSupport()
]
if ( PROD )
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
)
var node_config = {
devtool: "cheap-module-source-map",
entry: ["babel-polyfill", "./src/index.js"],
output: {
path: `${__dirname}/bin`,
filename: PROD ? "bundle.min.js" : "bundle.js",
libraryTarget: "commonjs2"
},
externals: [nodeExternals()],
target: "node",
node: {
__dirname: false
},
module: {
loaders: [
{
test: /.js?$/,
loader: "babel-loader",
exclude: /node_modules/,
query: {
presets: ["latest", "stage-0"],
plugins: ["transform-async-to-generator"]
}
},
{
test: /.json?$/,
loader: "json-loader"
}
]
},
plugins: plugins
}
var postProcess = function(err, stats) {
if (err) throw err
console.log(stats.toString("minimal"))
}
var compiler = webpack([node_config])
if (process.argv.indexOf("--compile") !== -1)
compiler.run(postProcess)
else if (process.argv.indexOf("--watch") !== -1)
compiler.watch(null, postProcess)