-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
62 lines (60 loc) · 1.42 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
const webpack = require("webpack"),
path = require("path"),
glob = require("glob"),
BundleTracker = require("webpack-bundle-tracker"),
babelrc = require("./babelrc"),
dev = process.env.NODE_ENV === "development";
const entry = () => {
let entry = {};
const pages = glob.sync("src/containers/*.js");
pages.forEach(page => {
const fileName = page
.split("/")
.pop()
.split(".")[0];
entry = {
...entry,
[fileName]: [
...(dev ? ["react-hot-loader/patch"] : []),
path.resolve(page),
...(dev
? [
"webpack-hot-middleware/client?path=http://localhost:9000/__webpack_hmr"
]
: [])
]
};
});
return entry;
};
module.exports = {
mode: dev ? "development" : "production",
devtool: dev ? "eval" : "source-map",
entry,
output: {
path: path.resolve("./core/static/pages/"),
filename: dev ? "[name].js" : "[name]-[hash].js",
publicPath: dev ? "http://localhost:9000/" : "/static/pages/"
},
module: {
rules: [
{
test: /\.js/,
use: {
loader: "babel-loader",
options: babelrc
},
exclude: "/node_modules/"
}
]
},
plugins: [
new BundleTracker({ filename: "./webpack-stats.json" }),
...(dev
? [
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
]
: [])
]
};