-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathrsbuild.config.ts
More file actions
134 lines (123 loc) · 4.19 KB
/
rsbuild.config.ts
File metadata and controls
134 lines (123 loc) · 4.19 KB
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
import { InjectManifest } from '@aaroon/workbox-rspack-plugin';
import { defineConfig, loadEnv } from '@rsbuild/core';
import { pluginEslint } from '@rsbuild/plugin-eslint';
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';
import { pluginSvgr } from '@rsbuild/plugin-svgr';
const { publicVars, rawPublicVars } = loadEnv({ prefixes: ['REACT_APP_'] });
export default defineConfig({
plugins: [
pluginReact(),
pluginSvgr({ mixedImport: true }),
pluginNodePolyfill(),
pluginSass(),
pluginEslint({
enable: process.env.NODE_ENV === 'development',
eslintPluginOptions: {
cwd: __dirname,
configType: 'flat'
}
})
],
server: {
port: 8000
},
tools: {
// TODO: See if still needed
rspack: config => {
// // avoid the entire process.env being inserted into the service worker
// // if SW_EXCLUDE_REGEXES is unset
// const definePlugin = config.plugins?.find(
// plugin => plugin.constructor.name === 'DefinePlugin'
// );
// const inlineProcessEnv = definePlugin.definitions['process.env'];
// if (!inlineProcessEnv.REACT_APP_SW_EXCLUDE_REGEXES) {
// inlineProcessEnv.REACT_APP_SW_EXCLUDE_REGEXES = undefined;
// }
// // add rules to pack WASM (for Sourceror)
// const wasmExtensionRegExp = /\.wasm$/;
// config.resolve.extensions.push('.wasm');
// config.module.rules.forEach(rule => {
// (rule.oneOf || []).forEach(oneOf => {
// if (oneOf.type === 'asset/resource') {
// oneOf.exclude.push(wasmExtensionRegExp);
// }
// });
// });
// // See https://webpack.js.org/configuration/experiments/#experiments.
// config.experiments = {
// syncWebAssembly: true
// };
// config.output.webassemblyModuleFilename = 'static/[hash].module.wasm';
// // workaround .mjs files by Acorn
// config.module.rules.push({
// test: /\.mjs$/,
// include: /node_modules/,
// type: 'javascript/auto',
// resolve: {
// fullySpecified: false
// }
// });
config.ignoreWarnings = [
(warning: any) => {
// Ignore the warnings that occur because js-slang uses dynamic imports
// to load Source modules
const moduleName = warning.moduleDescriptor?.name;
if (!moduleName) return false;
if (!/js-slang\/dist\/modules\/loader\/loaders.js/.test(moduleName)) return false;
return /Critical dependency: the request of a dependency is an expression/.test(
warning.message
);
}
// {
// // Ignore warnings for dependencies that do not ship with a source map.
// // This is because we cannot do anything about our dependencies.
// module: /node_modules/,
// message: /Failed to parse source map/
// },
// [
];
// config.plugins = [
// ...config.plugins,
// // Make environment variables available in the browser by polyfilling the 'process' Node.js module.
// new webpack.ProvidePlugin({
// process: 'process/browser'
// }),
// // Make the 'buffer' Node.js module available in the browser.
// new webpack.ProvidePlugin({
// Buffer: ['buffer', 'Buffer']
// })
// ];
config.plugins = [
...config.plugins,
new InjectManifest({
swSrc: './src/service-worker.ts',
swDest: 'service-worker.js',
maximumFileSizeToCacheInBytes: 20 * 1024 * 1024
})
];
// Workaround to suppress warnings caused by ts-morph in js-slang
// if (config.module) {
// config.module.noParse = /node_modules\/@ts-morph\/common\/dist\/typescript\.js$/;
// }
return config;
}
},
source: {
define: {
...publicVars,
'process.env': JSON.stringify(rawPublicVars)
}
},
html: {
template: './public/index.html',
favicon: './public/icons/favicon.ico'
},
output: {
distPath: {
root: './build'
},
sourceMap: true
}
});