-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.server.config.js
77 lines (76 loc) · 1.71 KB
/
webpack.server.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
const path = require("path"),
webpack = require("webpack"),
CleanWebpackPlugin = require("clean-webpack-plugin"),
HtmlWebpackPlugin = require("html-webpack-plugin"),
fs = require("fs");
const nodeModules = {};
fs
.readdirSync("node_modules")
.filter(function(x) {
return [".bin"].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = "commonjs " + mod;
});
module.exports = {
entry: ["babel-polyfill", "./server/server.js"],
target: "node",
output: {
path: path.join(__dirname, "build/server"),
filename: "server.js"
},
externals: nodeModules,
module: {
rules: [
{
test: /\.js$/,
include: path.join(__dirname, "server"),
exclude: /node_modules/,
use: {
loader: "babel-loader",
query: {
presets: ["react", "env"]
}
}
},
{
test: /\.json$/,
include: path.join(__dirname, "../config"),
exclude: /node_modules/,
use: { loader: "json" }
}
]
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
chunks: "initial",
minChunks: 3,
name: "commons",
enforce: true
},
vendor: {
chunks: "initial",
test: path.resolve(__dirname, "node_modules"),
name: "vendor",
enforce: true
}
}
}
},
resolve: {
// you can now require('file') instead of require('file.js')
extensions: [".js", ".json"]
},
plugins: [
new CleanWebpackPlugin(["build/server"], {
// Write logs to console.
verbose: true
}),
new HtmlWebpackPlugin({
filename: "index.html",
inject: "body"
})
]
};