-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrspack.config.ts
More file actions
195 lines (192 loc) · 5.19 KB
/
rspack.config.ts
File metadata and controls
195 lines (192 loc) · 5.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import { defineConfig } from '@meteorjs/rspack';
import { rspack } from '@rspack/core';
import { createRequire } from 'module';
import path from 'path';
import { VueLoaderPlugin } from 'vue-loader';
const require = createRequire(import.meta.url);
const projectRoot = process.cwd();
/**
* Rspack configuration for Meteor projects.
*
* Provides typed flags on the `Meteor` object, such as:
* - `Meteor.isClient` / `Meteor.isServer`
* - `Meteor.isDevelopment` / `Meteor.isProduction`
* - …and other flags available
*
* Use these flags to adjust your build settings based on environment.
*/
export default defineConfig((Meteor: any) => {
const isTestRun = Boolean(
Meteor.isTest ||
Meteor.isTestLike ||
Meteor.isTestFullApp ||
process.env.TEST_WATCH ||
process.env.METEOR_TEST
);
const shouldStubAppServer = Meteor.isServer && !Meteor.isTest && isTestRun;
if (Meteor.isServer) {
return {
plugins: [],
ignoreWarnings: [
{
module: /node_modules\/express\/lib\/view\.js/,
message: /Critical dependency: the request of a dependency is an expression/,
},
{
module: /node_modules\/routing-controllers\/.*importClassesFromDirectories\.js/,
message: /Critical dependency: the request of a dependency is an expression/,
},
{
module: /node_modules\/handlebars\/lib\/index\.js/,
message: /require\.extensions is not supported by Rspack/,
},
{
module: /node_modules\/hash-stream-validation\/index\.js/,
message: /fast-crc32c/,
},
{
module: /node_modules\/retry-request\/index\.js/,
message: /Can't resolve 'request'/,
},
],
module: {
rules: [
{
test: /\.(ts)$/,
exclude: /node_modules/,
loader: 'builtin:swc-loader',
options: {
// Merge the configuration from swc.config.js with specific options
jsc: {
//...swcConfig.jsc,
// Ensure baseUrl is an absolute path (SWC requires an absolute path)
baseUrl: projectRoot,
parser: {
syntax: 'typescript',
decorators: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
},
},
},
],
},
resolve: {
extensions: ['.ts', '.json'],
alias: {
'@api': '/imports/api',
'@server': '/imports/startup/server',
...(shouldStubAppServer
? { '/imports/startup/server': path.resolve(projectRoot, 'imports/startup/server/test-noop.ts') }
: {}),
},
// Improve module resolution stability
symlinks: true,
fullySpecified: false,
},
}
}
return {
...Meteor.isClient && {
plugins: [new VueLoaderPlugin(),
new rspack.DefinePlugin({
__VUE_OPTIONS_API__: JSON.stringify(true),
__VUE_PROD_DEVTOOLS__: JSON.stringify(false),
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(false),
})],
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
// Note, for the majority of features to be available, make sure this option is `true`
experimentalInlineMatchResource: true,
},
},
{
resourceQuery: /lang=sass/,
type: 'css/auto',
use: [
{
loader: 'sass-loader',
options: {
// using `modern-compiler` and `sass-embedded` together significantly improve build performance,
// requires `sass-loader >= 14.2.1`
api: 'modern-compiler',
implementation: require.resolve('sass-embedded'),
sassOptions: {
syntax: 'indented',
},
},
},
],
},
{
test: /\.sass$/,
type: 'css/auto',
use: [
{
loader: 'sass-loader',
options: {
// using `modern-compiler` and `sass-embedded` together significantly improve build performance,
// requires `sass-loader >= 14.2.1`
api: 'modern-compiler',
implementation: require.resolve('sass-embedded'),
sassOptions: {
syntax: 'indented',
},
},
},
],
},
{ test: /\.css$/, type: 'css' },
{
test: /\.(png|jpe?g|gif|svg|webp|ico)$/i,
type: 'asset/resource',
generator: { filename: 'assets/images/[name].[hash][ext]' },
},
{
test: /\.(ts)$/,
exclude: /node_modules/,
loader: 'builtin:swc-loader',
options: {
// Merge the configuration from swc.config.js with specific options
jsc: {
//...swcConfig.jsc,
// Ensure baseUrl is an absolute path (SWC requires an absolute path)
baseUrl: projectRoot,
parser: {
syntax: 'typescript',
decorators: true,
},
//target: 'es2020',
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
},
},
},
],
},
resolve: {
extensions: ['.ts', '.vue', '.json'],
alias: {
'@components': '/imports/ui/components',
'@views': '/imports/ui/views',
'@layouts': '/imports/ui/layouts',
'@routes': '/imports/ui/routes',
'@mixins': '/imports/ui/mixins',
'@typings': '/imports/ui/typings',
},
// Improve module resolution stability
symlinks: true,
fullySpecified: false,
},
},
};
});