-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.js
109 lines (96 loc) · 2.46 KB
/
webpack.config.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"use strict";
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const devServer = {
contentBase: path.resolve("dist"),
hot: true,
host: process.env.host || "localhost",
port: process.env.PORT || 5000
};
const webpackConfig = (env) => {
const config = {
entry: {
app: path.resolve("./src/core/bootstrap.js")
},
output: {
filename: "bundle.js",
chunkFilename: "[name].chunk.js",
path: path.join(__dirname, "dist")
},
module: {
rules: [
// eslint
{
enforce: "pre",
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
},
// babel
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
},
// html
{
test: /\.html$/,
loader: "raw-loader",
exclude: path.resolve("./src/index.html")
},
// css
{
test: /\.css$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}]
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
template: path.resolve("./src/index.html")
}),
new webpack.optimize.CommonsChunkPlugin({
name: "common",
filename: "common.js",
minChunks: (module) => {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf("node_modules") !== -1;
}
}),
new CleanWebpackPlugin(["dist"]),
new BundleAnalyzerPlugin()
]
};
if (env && env.dev) {
config.devServer = devServer;
config.plugins.push(
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
);
}
if (env && env.production) {
config.devtool = "source-map";
config.plugins.push(
new UglifyJSPlugin({
uglifyOptions: {
warnings: true
},
sourceMap: true
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
})
);
}
return config;
};
module.exports = webpackConfig;