-
Notifications
You must be signed in to change notification settings - Fork 478
/
webpack.renderer.config.js
139 lines (133 loc) · 3.58 KB
/
webpack.renderer.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* eslint-disable @typescript-eslint/no-var-requires */
const webpack = require("webpack");
const rules = require("./webpack.rules");
const plugins = require("./webpack.plugins");
const Path = require("path");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const ReactRefreshTypeScript = require("react-refresh-typescript");
const isDevelopment = process.env.NODE_ENV !== "production";
const rendererRules = [
{
test: /\.worker\.(ts|js)$/,
exclude: /(node_modules|.webpack)/,
rules: [
{
loader: "worker-loader",
options: { publicPath: "../" },
},
{
loader: "ts-loader",
options: {
getCustomTransformers: isDevelopment
? () => ({
before: [ReactRefreshTypeScript()],
})
: undefined,
transpileOnly: true,
},
},
],
},
{
test: /^(?!.*\.worker\.ts$).*\.(ts|tsx|js|jsx)$/,
exclude: /(node_modules|.webpack)/,
use: [
{
loader: require.resolve("ts-loader"),
options: {
getCustomTransformers: isDevelopment
? () => ({
before: [ReactRefreshTypeScript()],
})
: undefined,
transpileOnly: true,
},
},
],
},
...rules.slice(1), // Remove global ts-loader rule replaced with ReactRefreshTypeScript version defined above
{
test: /\.css$/,
use: [{ loader: "style-loader" }, { loader: "css-loader" }],
},
];
const rendererPlugins = [
...plugins,
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
];
if (isDevelopment) {
rendererPlugins.push(new ReactRefreshWebpackPlugin());
}
const srcPath = (subdir) => {
return Path.join(__dirname, "src", subdir);
};
module.exports = {
// Put your normal webpack config below here
target: "web",
node: {
__dirname: true,
__filename: true,
},
module: {
rules: rendererRules,
},
optimization: {
minimize: false,
splitChunks: {
cacheGroups: {
"vendor-react": {
name: "vendor-react",
test: /[\\/]node_modules[\\/](react.*?|redux.*?)[\\/]/,
chunks: "initial",
priority: 2,
},
"vendor-scriptracker": {
name: "vendor-scriptracker",
test: /[\\/]src[\\/]lib[\\/]vendor[\\/]scriptracker[\\/]/,
chunks: "all",
priority: 2,
},
"vendor-hotloader": {
name: "vendor-hotloader",
test: /[\\/]node_modules[\\/]@hot-loader[\\/]/,
chunks: "all",
priority: 2,
},
"vendor-lodash": {
name: "vendor-lodash",
test: /[\\/]node_modules[\\/]lodash[\\/]/,
chunks: "all",
priority: 2,
},
},
},
},
plugins: rendererPlugins,
resolve: {
extensions: [".js", ".ts", ".jsx", ".tsx", ".wasm", ".css"],
alias: {
store: srcPath("store"),
components: srcPath("components"),
lang: srcPath("lang"),
lib: srcPath("lib"),
ui: srcPath("components/ui"),
renderer: srcPath("renderer"),
shared: srcPath("shared"),
assets: srcPath("assets"),
consts: srcPath("consts.ts"),
wasm: Path.join(__dirname, "appData/wasm"),
"contributors.json": Path.join(__dirname, "contributors.json"),
"contributors-external.json": Path.join(
__dirname,
"contributors-external.json"
),
"patrons.json": Path.join(__dirname, "patrons.json"),
},
fallback: {
path: require.resolve("path-browserify"),
buffer: require.resolve("buffer"),
},
},
};