@meteorjs/rspack 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/rspack.config.js +41 -31
package/package.json
CHANGED
package/rspack.config.js
CHANGED
|
@@ -116,6 +116,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
116
116
|
const isClient = Meteor.isClient;
|
|
117
117
|
const isRun = Meteor.isRun;
|
|
118
118
|
const isReactEnabled = Meteor.isReactEnabled;
|
|
119
|
+
const isTestModule = Meteor.isTestModule;
|
|
119
120
|
const mode = isProd ? 'production' : 'development';
|
|
120
121
|
|
|
121
122
|
const isTypescriptEnabled = Meteor.isTypescriptEnabled || false;
|
|
@@ -141,10 +142,10 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
141
142
|
|
|
142
143
|
// Determine output directories
|
|
143
144
|
const clientOutputDir = path.resolve(process.cwd(), 'public');
|
|
144
|
-
const serverOutputDir = path.resolve(process.cwd(), '
|
|
145
|
+
const serverOutputDir = path.resolve(process.cwd(), 'private');
|
|
145
146
|
|
|
146
147
|
// Determine context for bundles and assets
|
|
147
|
-
const buildContext = Meteor.buildContext || '
|
|
148
|
+
const buildContext = Meteor.buildContext || '_build';
|
|
148
149
|
const bundlesContext = Meteor.bundlesContext || 'bundles';
|
|
149
150
|
const assetsContext = Meteor.assetsContext || 'assets';
|
|
150
151
|
|
|
@@ -161,7 +162,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
161
162
|
});
|
|
162
163
|
const externals = [
|
|
163
164
|
/^meteor.*/,
|
|
164
|
-
...(isReactEnabled ? [/^react$/, /^react-dom$/] : [])
|
|
165
|
+
...(isReactEnabled ? [/^react$/, /^react-dom$/] : []),
|
|
165
166
|
];
|
|
166
167
|
const alias = {
|
|
167
168
|
'/': path.resolve(process.cwd()),
|
|
@@ -185,16 +186,33 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
185
186
|
|
|
186
187
|
const reactRefreshModule = isReactEnabled ? safeRequire('@rspack/plugin-react-refresh') : null;
|
|
187
188
|
|
|
189
|
+
const requireExternalsPlugin = new RequireExternalsPlugin({
|
|
190
|
+
filePath: path.join(buildContext, runPath),
|
|
191
|
+
...(Meteor.isBlazeEnabled && {
|
|
192
|
+
externals: /\.html$/,
|
|
193
|
+
externalMap: (module) => {
|
|
194
|
+
const { request, context } = module;
|
|
195
|
+
if (request.endsWith('.html')) {
|
|
196
|
+
const relContext = path.relative(process.cwd(), context);
|
|
197
|
+
const { name } = path.parse(request);
|
|
198
|
+
return `./${relContext}/template.${name}.js`;
|
|
199
|
+
}
|
|
200
|
+
return request;
|
|
201
|
+
},
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const clientNameConfig = `[${isTest && 'test-' || ''}${isTestModule && 'module' || 'client'}-rspack]`;
|
|
188
206
|
// Base client config
|
|
189
207
|
let clientConfig = {
|
|
190
|
-
name:
|
|
208
|
+
name: clientNameConfig,
|
|
191
209
|
target: 'web',
|
|
192
210
|
mode,
|
|
193
211
|
entry: path.resolve(process.cwd(), buildContext, entryPath),
|
|
194
212
|
output: {
|
|
195
213
|
path: clientOutputDir,
|
|
196
214
|
filename: () =>
|
|
197
|
-
|
|
215
|
+
isRun && !isTest ? outputFilename : `../${buildContext}/${outputPath}`,
|
|
198
216
|
libraryTarget: 'commonjs',
|
|
199
217
|
publicPath: '/',
|
|
200
218
|
chunkFilename: `${bundlesContext}/[id].[chunkhash].js`,
|
|
@@ -221,28 +239,12 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
221
239
|
resolve: { extensions, alias },
|
|
222
240
|
externals,
|
|
223
241
|
plugins: [
|
|
224
|
-
...
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
filePath: path.join(buildContext, runPath),
|
|
231
|
-
...(Meteor.isBlazeEnabled && {
|
|
232
|
-
externals: /\.html$/,
|
|
233
|
-
externalMap: (module) => {
|
|
234
|
-
const { request, context } = module;
|
|
235
|
-
if (request.endsWith('.html')) {
|
|
236
|
-
const relContext = path.relative(process.cwd(), context);
|
|
237
|
-
const { name } = path.parse(request);
|
|
238
|
-
return `./${relContext}/template.${name}.js`;
|
|
239
|
-
}
|
|
240
|
-
return request;
|
|
241
|
-
},
|
|
242
|
-
}),
|
|
243
|
-
}),
|
|
244
|
-
].filter(Boolean)
|
|
245
|
-
: []),
|
|
242
|
+
...[
|
|
243
|
+
...(isReactEnabled && reactRefreshModule
|
|
244
|
+
? [new reactRefreshModule()]
|
|
245
|
+
: []),
|
|
246
|
+
requireExternalsPlugin,
|
|
247
|
+
].filter(Boolean),
|
|
246
248
|
new DefinePlugin({
|
|
247
249
|
'Meteor.isClient': JSON.stringify(true),
|
|
248
250
|
'Meteor.isServer': JSON.stringify(false),
|
|
@@ -256,8 +258,8 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
256
258
|
}),
|
|
257
259
|
],
|
|
258
260
|
watchOptions,
|
|
259
|
-
devtool: isDev ? 'source-map' : 'hidden-source-map',
|
|
260
|
-
...(isRun && {
|
|
261
|
+
devtool: isDev || isTest ? 'source-map' : 'hidden-source-map',
|
|
262
|
+
...(isRun && !isTest && {
|
|
261
263
|
devServer: {
|
|
262
264
|
static: { directory: clientOutputDir, publicPath: '/__rspack__/' },
|
|
263
265
|
hot: true,
|
|
@@ -271,9 +273,10 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
271
273
|
}),
|
|
272
274
|
};
|
|
273
275
|
|
|
276
|
+
const serverNameConfig = `[${isTest && 'test-' || ''}${isTestModule && 'module' || 'server'}-rspack]`;
|
|
274
277
|
// Base server config
|
|
275
278
|
let serverConfig = {
|
|
276
|
-
name:
|
|
279
|
+
name: serverNameConfig,
|
|
277
280
|
target: 'node',
|
|
278
281
|
mode,
|
|
279
282
|
entry: path.resolve(process.cwd(), buildContext, entryPath),
|
|
@@ -287,6 +290,12 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
287
290
|
optimization: { usedExports: true },
|
|
288
291
|
module: {
|
|
289
292
|
rules: [swcConfigRule, ...extraRules],
|
|
293
|
+
parser: {
|
|
294
|
+
javascript: {
|
|
295
|
+
// Dynamic imports on the server are treated as bundled in the same chunk
|
|
296
|
+
dynamicImportMode: 'eager',
|
|
297
|
+
},
|
|
298
|
+
},
|
|
290
299
|
},
|
|
291
300
|
resolve: {
|
|
292
301
|
extensions,
|
|
@@ -307,10 +316,11 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
307
316
|
banner: bannerOutput,
|
|
308
317
|
entryOnly: true,
|
|
309
318
|
}),
|
|
319
|
+
isTestModule && requireExternalsPlugin,
|
|
310
320
|
],
|
|
311
321
|
watchOptions,
|
|
312
322
|
devtool: isRun ? 'source-map' : 'hidden-source-map',
|
|
313
|
-
...(isRun &&
|
|
323
|
+
...((isRun || isTest) &&
|
|
314
324
|
createCacheStrategy(mode)
|
|
315
325
|
),
|
|
316
326
|
};
|