-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
113 lines (112 loc) · 3.41 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
110
111
112
113
const path = require("path");
const nodeExternals = require("webpack-node-externals");
const WebpackShellPlugin = require("webpack-shell-plugin-alt");
const CircularDependencyPlugin = require("circular-dependency-plugin");
const webpack = require("webpack");
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = (env, argv) => {
return [
{
// Server Config
// name: 'server',
entry: {
server: "./src/server/server-dev.tsx",
},
output: {
path: path.join(__dirname, "build"),
publicPath: "/",
filename: "[name].js",
chunkFilename: "[name]-bundle.js",
},
mode: argv.mode,
optimization: {
usedExports: true,
},
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 /
},
externals: [
nodeExternals({
allowlist: ["mithril"], // For resolve alias in target node
}),
], // Need this to avoid error when working with Express
module: {
rules: [
{
test: /\.tsx?$/,
exclude: path.resolve(__dirname, "node_modules"),
loader: "ts-loader",
// options: {
// configFile: 'tsconfig-server.json',
// },
},
],
},
resolve: {
extensions: [".mjs", ".tsx", ".ts", ".js", ".jsx"],
alias: {
mithril$: path.resolve(__dirname, "lib/m.js"),
},
},
plugins: [
new WebpackShellPlugin({
onBuildEnd: ["npm run start"],
}),
// new BundleAnalyzerPlugin({generateStatsFile: true, analyzerMode: false}),
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /a\.js|node_modules/,
// add errors to webpack instead of warnings
failOnError: true,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles: false,
// set the current working directory for displaying module paths
cwd: process.cwd(),
}),
new webpack.EnvironmentPlugin({
BROWSER_ENV: false,
DEBUG: argv.mode === "development",
}),
],
},
{
// Client Config
// name: 'client',
entry: "./src/client/app.tsx",
output: {
path: path.resolve(__dirname, "./build/assets"),
filename: "js/app.js",
chunkFilename: "js/[name]-bundle.js",
},
module: {
rules: [
{
test: /\.tsx$/,
exclude: path.resolve(__dirname, "node_modules"),
loader: "ts-loader",
// options: {
// configFile: 'tsconfig-client.json',
// },
},
],
},
resolve: {
extensions: [".mjs", ".tsx", ".ts", ".js", ".jsx"],
alias: {
mithril$: path.resolve(__dirname, "lib/m.js"),
},
},
plugins: [
new webpack.EnvironmentPlugin({
BROWSER_ENV: true,
DEBUG: argv.mode === "development",
}),
// new BundleAnalyzerPlugin({generateStatsFile: true, analyzerMode: false}),
],
},
];
};