-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
155 lines (147 loc) · 3.69 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* eslint-disable */
const path = require("path");
const fs = require("fs");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const merge = require("webpack-merge").merge;
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const webpack = require("webpack");
const isDevelopment = process.env.NODE_ENV !== "production";
const baseConfig = {
mode: isDevelopment ? "development" : "production",
context: __dirname,
resolve: {
extensions: [".ts", ".tsx", ".js"],
alias: {
common: path.join(__dirname, "src", "common"),
},
},
module: {
rules: [
{
test: /\.css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
importLoaders: 3,
modules: false,
},
},
],
},
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve("babel-loader"),
options: {
...require("./babel.config"),
plugins: [
...(require("./babel.config").plugins || []),
isDevelopment && require.resolve("react-refresh/babel"),
].filter(Boolean),
},
},
],
},
{
test: /\.(woff2?|ttf|eot|svg|otf|woff2|otf|ttf)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/resource",
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
isDevelopment && new webpack.HotModuleReplacementPlugin(),
isDevelopment &&
new ReactRefreshWebpackPlugin({
overlay: {
sockIntegration: "wds",
sockPort: 8080,
},
}),
].filter(Boolean),
};
let wsPort = 8080;
function makeConfig(kind, name) {
wsPort += 1;
const htmlTemplate = fs.existsSync(
path.join(__dirname, "src", kind, `index.${name}.html`)
)
? path.join(__dirname, "src", kind, `index.${name}.html`)
: path.join(__dirname, "src", kind, `index.html`);
return merge(baseConfig, {
name: name,
entry: [
require.resolve("webpack-dev-server/client") +
`?http://0.0.0.0:${wsPort}`,
`./src/${kind}/index.${name}.tsx`,
],
output: {
path: path.join(__dirname, kind),
filename: `${name}.bundle.js`,
uniqueName: name,
},
plugins: [
new HtmlWebpackPlugin({
filename: path.join(__dirname, kind, `${name}.html`),
template: htmlTemplate,
}),
],
devServer: {
hot: true,
writeToDisk: true,
injectHot: true,
sockPort: wsPort,
public: `localhost:${wsPort}`,
inline: true,
port: wsPort,
},
});
}
const dashboards = fs
.readdirSync(path.join(__dirname, "src", "dashboard"))
.map((x) => x.match(/index\.(.+)\.tsx?$/i))
.filter(Boolean)
.map((x) => x[1])
.map((x) => makeConfig("dashboard", x));
const graphics = fs
.readdirSync(path.join(__dirname, "src", "graphics"))
.map((x) => x.match(/index\.(.+)\.tsx?$/i))
.filter(Boolean)
.map((x) => x[1])
.map((x) => makeConfig("graphics", x));
const config = [
...dashboards,
...graphics,
{
name: "extension",
mode: "development",
entry: "./src/extension/index.extension.ts",
target: "node",
module: {
rules: [
{
test: /\.tsx?/,
loader: "ts-loader",
exclude: /node-modules/,
},
],
},
externalsPresets: {
node: true,
},
devtool: false,
output: {
path: __dirname,
filename: "extension.js",
library: {
type: "commonjs2",
},
},
},
];
module.exports = config;