-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
91 lines (82 loc) · 2.21 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
const path = require("path");
const nodeExternals = require("webpack-node-externals");
const CopyPlugin = require("copy-webpack-plugin");
const bundleOptimizations = {
runtimeChunk: "single",
splitChunks: {
chunks: "all",
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace("@", "")}`;
},
},
},
},
};
const tsLoaderRules = {
test: /\.ts?$/,
use: "ts-loader",
exclude: /node_modules/,
};
const outputFormatting = {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
chunkFilename: "[name].[contenthash].js",
};
const sharedConfig = {
entry: {
seabot: ["./src/server.ts"],
},
target: "node",
externals: [nodeExternals()],
module: {
rules: [tsLoaderRules],
},
resolve: {
extensions: [".ts", ".js"],
},
output: outputFormatting,
optimization: bundleOptimizations,
};
const package_patterns = [
"package.json",
"package-lock.json"
]
const prodWebpackConfig = {
mode: "production",
name: "prod",
...sharedConfig,
plugins: [
new CopyPlugin({
patterns: [
...package_patterns,
"src/seabotConfig.json",
],
}),
],
};
const devWebpackConfig = {
mode: "development",
name: "dev",
...sharedConfig,
plugins: [
new CopyPlugin({
// allows us to copy different config files to dist at build time
patterns: [
...package_patterns,
{ from: "src/devConfig.json", to: "seabotConfig.json" }
],
}),
],
};
module.exports = [prodWebpackConfig, devWebpackConfig];