-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
81 lines (77 loc) · 2.58 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
const path = require("path");
const webpack = require("webpack");
const merge = require("webpack-merge");
const nodeExternals = require("webpack-node-externals");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const clientModeConfig = env => require(`./webpack/webpack.${env}.js`)(env);
const serverModeConfig = (env = "prod") =>
require(`./webpack/webpack.server.${env}.js`)(env);
module.exports = ({ mode, project } = { mode: "prod", project: "client" }) => {
if (project === "server") {
// bundling for sever projects
return merge(
{
entry: path.resolve("./src/Server/server.js"),
output: {
filename: "server.bundle.js",
path: path.join(__dirname, "ServerBundle"),
},
resolve: {
alias: {
mocks: path.resolve(__dirname, "./src/__mocks__"),
utils: path.resolve(__dirname, "./utils"),
assets: path.resolve(__dirname, "./assets"),
src: path.resolve(__dirname, "./src/"),
},
},
target: "node",
node: {
// Need this when working with express, otherwise the build fails
__dirname: false, // if you don't put this is, __dirname
__filename: false, // and __filename return blank or /
fs: "empty",
},
externals: [nodeExternals()],
},
serverModeConfig(mode)
);
} else {
// bundling for client side projects
return merge(
{
mode,
entry: "./index.js",
output: {
filename: "./client.bundle.js",
path: path.join(__dirname, "ClientBundle"),
},
resolve: {
alias: {
Components: path.resolve(__dirname, "./src/Client/Components"),
css: path.resolve(__dirname, "./src/Client/css"),
mocks: path.resolve(__dirname, "./src/__mocks__"),
utils: path.resolve(__dirname, "./utils"),
assets: path.resolve(__dirname, "./assets"),
src: path.resolve(__dirname, "./src/"),
},
modules: [path.resolve(__dirname, "./src/Client"), "node_modules"],
},
plugins: [
new webpack.ProgressPlugin(),
new HtmlWebpackPlugin({
template: path.resolve("./webpack/template.ejs"),
templateParameters: {
title: "React BoilerPlate v3", // name of the app
},
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
},
}),
],
},
clientModeConfig(mode)
);
}
};