forked from asiryk/slot-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rspack.config.ts
75 lines (70 loc) · 1.55 KB
/
rspack.config.ts
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
const path = require("path");
const rspack = require("@rspack/core");
const HTMLPlugin = require("html-webpack-plugin");
const IS_DEV_MODE = process.argv.reduce((acc, arg) => acc || arg.includes("development"), false);
const BUILD_PATH = path.resolve("dist");
module.exports = {
devtool: IS_DEV_MODE && "cheap-module-source-map",
entry: "./src/index.ts",
output: {
path: BUILD_PATH,
filename: "[name].[contenthash:8].js",
clean: true,
},
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: getLoaders(),
},
plugins: getPlugins(),
devServer: {
static: {
directory: path.join(__dirname, BUILD_PATH),
},
compress: false,
port: 4200,
hot: true,
},
optimization: getOptimizations(),
};
function getOptimizations() {
return {
minimize: !IS_DEV_MODE,
splitChunks: {
chunks: "all",
},
runtimeChunk: {
name: (entrypoint: any) => `runtime-${entrypoint.name}`,
},
};
}
function getLoaders() {
return [
{
test: /\.tsx?$/,
exclude: [/node_modules/],
loader: "builtin:swc-loader",
options: {
jsc: {
parser: {
syntax: "typescript",
},
},
},
type: "javascript/auto",
},
];
}
function getPlugins() {
return [
new HTMLPlugin({ template: "./src/index.html" }),
new rspack.CopyRspackPlugin({
patterns: [
{ from: "./src/public/", to: "public/" },
{ from: "./src/styles/", to: "styles/" },
{ from: "./src/assets/", to: "assets/" },
],
}),
];
}