forked from magcius/noclip.website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrspack.config.ts
109 lines (106 loc) · 2.66 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
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
import * as rspack from '@rspack/core';
import * as fs from 'node:fs';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { GitRevisionPlugin } from 'git-revision-webpack-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
const targets = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8')).browserslist;
const gitRevision = new GitRevisionPlugin();
const config: rspack.Configuration = {
context: __dirname,
entry: {
main: './src/main.ts',
},
output: {
path: __dirname + '/dist',
filename: '[name]-[contenthash].js',
},
// Disable asset size limit warnings
performance: false,
resolve: {
extensionAlias: {
'.js': ['.js', '.ts'],
},
},
module: {
rules: [
{
test: /\.(png|woff2)$/,
type: 'asset/resource',
},
{
test: /\.glsl$/,
type: 'asset/source',
},
{
test: /\.(j|t)s$/,
exclude: [/[\\/]node_modules[\\/]/],
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
decorators: true,
},
transform: {
useDefineForClassFields: false,
},
externalHelpers: true,
},
env: { targets },
},
},
],
},
plugins: [
new rspack.DefinePlugin({
'__COMMIT_HASH': JSON.stringify(gitRevision.commithash()),
}),
new rspack.EnvironmentPlugin(['NODE_ENV']),
new rspack.IgnorePlugin({
// Workaround for broken libraries
resourceRegExp: /^(fs|path)$/,
}),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
'**/*',
'!data',
'!data/**/*',
'!.htaccess',
],
}),
new HtmlWebpackPlugin({
chunks: ['main'],
filename: 'index.html',
template: './src/index.html',
}),
new HtmlWebpackPlugin({
chunks: ['main'],
filename: 'embed.html',
template: './src/index.html',
}),
new rspack.CopyRspackPlugin({
// All .wasm files are currently expected to be at the root
patterns: [
{ from: 'src/**/*.wasm', to: '[name][ext]' },
{ from: 'node_modules/librw/lib/librw.wasm', to: '[name][ext]' },
],
}),
// Run type checking asynchronously
new ForkTsCheckerWebpackPlugin(),
],
devServer: {
static: {
directory: './data',
publicPath: '/data/',
watch: false,
},
compress: true,
},
optimization: {
minimizer: [
new rspack.SwcJsMinimizerRspackPlugin(),
]
},
};
export default config;