-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
webpack.config.babel.js
50 lines (46 loc) · 1.21 KB
/
webpack.config.babel.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
import path from "path";
import webpack from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
function insrc(...parts) {
return new RegExp("^" + path.join(__dirname, "src", ...parts) + "$");
}
function getNameBySuffix(stats, suffix) {
return stats.assets.find(asset =>
asset.name === suffix ||
asset.name.slice(-suffix.length - 1) === "." + suffix
).name;
}
const DEBUG = process.env.NODE_ENV !== "production";
const JS_NAME = DEBUG ? "webm.js" : "[chunkhash:10].webm.js";
const HTML_MINIFIER = DEBUG ? false : {
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
};
const COMMON_PLUGINS = [
new HtmlWebpackPlugin({
minify: HTML_MINIFIER,
template: path.join("src", "index", "index.html"),
getNameBySuffix,
}),
];
const PLUGINS = DEBUG ? COMMON_PLUGINS : COMMON_PLUGINS.concat([
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
output: {comments: false},
compress: {warnings: false},
}),
]);
export default {
entry: "./src/index",
output: {
path: path.join(__dirname, "dist"),
filename: JS_NAME,
},
module: {
loaders: [
{test: insrc(".+\\.js"), loader: "babel"},
],
},
plugins: PLUGINS,
};