@meteorjs/rspack 0.0.24 → 0.0.25

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.
@@ -0,0 +1,9 @@
1
+ {
2
+ const ctx = import.meta.webpackContext('/', {
3
+ recursive: true,
4
+ regExp: /\.app-?(?:test|spec)s?\.[^.]+$/,
5
+ exclude: /(^|\/)(node_modules|\.meteor|_build)(\/|$)/,
6
+ mode: 'eager',
7
+ });
8
+ ctx.keys().forEach(ctx);
9
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  const ctx = import.meta.webpackContext('/', {
3
3
  recursive: true,
4
- regExp: /\.(?:app-)?(?:test|spec)s?\.[^.]+$/,
4
+ regExp: /\.(?:test|spec)s?\.[^.]+$/,
5
5
  exclude: /(^|\/)(node_modules|\.meteor|_build)(\/|$)/,
6
6
  mode: 'eager',
7
7
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteorjs/rspack",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "Configuration logic for using Rspack in Meteor projects",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -13,7 +13,7 @@ export function loadHtmlRspackPluginFromHost(compiler) {
13
13
 
14
14
  /**
15
15
  * Rspack plugin to:
16
- * 1. Remove the injected `client-rspack.js` script tag
16
+ * 1. Remove the injected `*-rspack.js` script tags
17
17
  * 2. Strip <!doctype> and <html>…</html> wrappers from the final HTML
18
18
  */
19
19
  export default class RspackMeteorHtmlPlugin {
@@ -26,11 +26,11 @@ export default class RspackMeteorHtmlPlugin {
26
26
  compiler.hooks.compilation.tap('RspackMeteorHtmlPlugin', compilation => {
27
27
  const hooks = HtmlRspackPlugin.getCompilationHooks(compilation);
28
28
 
29
- // remove <script src=".../client-rspack.js">
29
+ // remove <script src="...*-rspack.js">
30
30
  hooks.alterAssetTags.tap('RspackMeteorHtmlPlugin', data => {
31
31
  data.assetTags.scripts = data.assetTags.scripts.filter(t => {
32
32
  const src = t.attributes?.src || t.asset || '';
33
- return !(t.tagName === 'script' && /(?:^|\/)client-rspack\.js$/i.test(src));
33
+ return !(t.tagName === 'script' && /(?:^|\/)[^\/]*-rspack\.js$/i.test(src));
34
34
  });
35
35
  });
36
36
 
package/rspack.config.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { DefinePlugin, BannerPlugin } from '@rspack/core';
2
2
  import fs from 'fs';
3
3
  import { createRequire } from 'module';
4
+ import { inspect } from 'node:util';
4
5
  import path from 'path';
5
6
  import { merge } from 'webpack-merge';
6
- import { inspect } from "node:util";
7
7
 
8
- import { RequireExternalsPlugin } from './plugins/RequireExtenalsPlugin.js';
9
- import { getMeteorAppSwcConfig } from "./lib/swc.js";
10
8
  import { mergeSplitOverlap } from './lib/mergeRulesSplitOverlap.js';
11
- import CleanBuildAssetsPlugin from "./plugins/CleanBuildAssetsPlugin.js";
9
+ import { getMeteorAppSwcConfig } from './lib/swc.js';
10
+ import CleanBuildAssetsPlugin from './plugins/CleanBuildAssetsPlugin.js';
12
11
  import HtmlRspackPlugin from './plugins/HtmlRspackPlugin.js';
12
+ import { RequireExternalsPlugin } from './plugins/RequireExtenalsPlugin.js';
13
13
 
14
14
  const require = createRequire(import.meta.url);
15
15
 
@@ -46,7 +46,13 @@ function createCacheStrategy(mode) {
46
46
  }
47
47
 
48
48
  // SWC loader rule (JSX/JS)
49
- function createSwcConfig({ isTypescriptEnabled, isJsxEnabled, isTsxEnabled, externalHelpers, isDevEnvironment }) {
49
+ function createSwcConfig({
50
+ isTypescriptEnabled,
51
+ isJsxEnabled,
52
+ isTsxEnabled,
53
+ externalHelpers,
54
+ isDevEnvironment,
55
+ }) {
50
56
  const defaultConfig = {
51
57
  jsc: {
52
58
  baseUrl: process.cwd(),
@@ -122,6 +128,7 @@ export default function (inMeteor = {}, argv = {}) {
122
128
  const isReactEnabled = Meteor.isReactEnabled;
123
129
  const isTestModule = Meteor.isTestModule;
124
130
  const isTestEager = Meteor.isTestEager;
131
+ const isTestFullApp = Meteor.isTestFullApp;
125
132
  const swcExternalHelpers = Meteor.swcExternalHelpers;
126
133
  const mode = isProd ? 'production' : 'development';
127
134
 
@@ -179,21 +186,22 @@ export default function (inMeteor = {}, argv = {}) {
179
186
  <% } %>
180
187
  </body>
181
188
  `,
182
- ...options
189
+ ...options,
183
190
  });
184
191
  };
185
192
 
186
193
  // Set watch options
187
194
  const watchOptions = {
188
195
  ...defaultWatchOptions,
189
- ...isTest && isTestEager && {
190
- ignored: [
191
- ...defaultWatchOptions.ignored,
192
- '**/_build/**',
193
- '**/.meteor/local/**',
194
- '**/node_modules/**',
195
- ],
196
- },
196
+ ...(isTest &&
197
+ isTestEager && {
198
+ ignored: [
199
+ ...defaultWatchOptions.ignored,
200
+ '**/_build/**',
201
+ '**/.meteor/local/**',
202
+ '**/node_modules/**',
203
+ ],
204
+ }),
197
205
  };
198
206
 
199
207
  if (Meteor.isDebug || Meteor.isVerbose) {
@@ -235,21 +243,25 @@ export default function (inMeteor = {}, argv = {}) {
235
243
  : []),
236
244
  ];
237
245
 
238
- const reactRefreshModule = isReactEnabled ? safeRequire('@rspack/plugin-react-refresh') : null;
246
+ const reactRefreshModule = isReactEnabled
247
+ ? safeRequire('@rspack/plugin-react-refresh')
248
+ : null;
239
249
 
240
250
  const requireExternalsPlugin = new RequireExternalsPlugin({
241
251
  filePath: path.join(buildContext, runPath),
242
252
  ...(Meteor.isBlazeEnabled && {
243
253
  externals: /\.html$/,
244
- isEagerImport: (module) => module.endsWith('.html'),
245
- ...isProd && {
254
+ isEagerImport: module => module.endsWith('.html'),
255
+ ...(isProd && {
246
256
  lastImports: [`./${outputFilename}`],
247
- },
257
+ }),
248
258
  }),
249
259
  enableGlobalPolyfill: isDevEnvironment,
250
260
  });
251
261
 
252
- const clientNameConfig = `[${isTest && 'test-' || ''}${isTestModule && 'module' || 'client'}-rspack]`;
262
+ const clientNameConfig = `[${(isTest && 'test-') || ''}${
263
+ (isTestModule && 'module') || 'client'
264
+ }-rspack]`;
253
265
  // Base client config
254
266
  let clientConfig = {
255
267
  name: clientNameConfig,
@@ -293,9 +305,13 @@ export default function (inMeteor = {}, argv = {}) {
293
305
  resolve: { extensions, alias },
294
306
  externals,
295
307
  plugins: [
296
- ...(isProd ? [
297
- new CleanBuildAssetsPlugin({ verbose: Meteor.isDebug || Meteor.isVerbose }),
298
- ] : []),
308
+ ...(isProd
309
+ ? [
310
+ new CleanBuildAssetsPlugin({
311
+ verbose: Meteor.isDebug || Meteor.isVerbose,
312
+ }),
313
+ ]
314
+ : []),
299
315
  ...[
300
316
  ...(isReactEnabled && reactRefreshModule && isDevEnvironment
301
317
  ? [new reactRefreshModule()]
@@ -325,7 +341,7 @@ export default function (inMeteor = {}, argv = {}) {
325
341
  ...(Meteor.isBlazeEnabled && { hot: false }),
326
342
  port: Meteor.devServerPort || 8080,
327
343
  devMiddleware: {
328
- writeToDisk: (filePath) =>
344
+ writeToDisk: filePath =>
329
345
  /\.(html)$/.test(filePath) && !filePath.includes('.hot-update.'),
330
346
  },
331
347
  },
@@ -333,15 +349,21 @@ export default function (inMeteor = {}, argv = {}) {
333
349
  experiments: { css: true },
334
350
  };
335
351
 
336
- const serverNameConfig = `[${isTest && 'test-' || ''}${isTestModule && 'module' || 'server'}-rspack]`;
352
+ const serverEntry =
353
+ isTest && isTestEager && isTestFullApp
354
+ ? 'node_modules/@meteorjs/rspack/entries/eager-app-tests.js'
355
+ : isTest && isTestEager
356
+ ? 'node_modules/@meteorjs/rspack/entries/eager-tests.js'
357
+ : path.resolve(process.cwd(), buildContext, entryPath);
358
+ const serverNameConfig = `[${(isTest && 'test-') || ''}${
359
+ (isTestModule && 'module') || 'server'
360
+ }-rspack]`;
337
361
  // Base server config
338
362
  let serverConfig = {
339
363
  name: serverNameConfig,
340
364
  target: 'node',
341
365
  mode,
342
- entry: isTest && isTestEager
343
- ? "node_modules/@meteorjs/rspack/entries/eager-tests.js"
344
- : path.resolve(process.cwd(), buildContext, entryPath),
366
+ entry: serverEntry,
345
367
  output: {
346
368
  path: serverOutputDir,
347
369
  filename: () => `../${buildContext}/${outputPath}`,
@@ -370,16 +392,16 @@ export default function (inMeteor = {}, argv = {}) {
370
392
  new DefinePlugin(
371
393
  isTest && (isTestModule || isTestEager)
372
394
  ? {
373
- "Meteor.isTest": JSON.stringify(isTest),
374
- "Meteor.isDevelopment": JSON.stringify(isDev),
395
+ 'Meteor.isTest': JSON.stringify(isTest),
396
+ 'Meteor.isDevelopment': JSON.stringify(isDev),
375
397
  }
376
398
  : {
377
- "Meteor.isClient": JSON.stringify(false),
378
- "Meteor.isServer": JSON.stringify(true),
379
- "Meteor.isTest": JSON.stringify(isTest),
380
- "Meteor.isDevelopment": JSON.stringify(isDev),
381
- "Meteor.isProduction": JSON.stringify(isProd),
382
- }
399
+ 'Meteor.isClient': JSON.stringify(false),
400
+ 'Meteor.isServer': JSON.stringify(true),
401
+ 'Meteor.isTest': JSON.stringify(isTest),
402
+ 'Meteor.isDevelopment': JSON.stringify(isDev),
403
+ 'Meteor.isProduction': JSON.stringify(isProd),
404
+ },
383
405
  ),
384
406
  new BannerPlugin({
385
407
  banner: bannerOutput,
@@ -389,9 +411,8 @@ export default function (inMeteor = {}, argv = {}) {
389
411
  ],
390
412
  watchOptions,
391
413
  devtool: isDevEnvironment || isTest ? 'source-map' : 'hidden-source-map',
392
- ...((isDevEnvironment || isTest && !isTestEager) &&
393
- createCacheStrategy(mode)
394
- ),
414
+ ...((isDevEnvironment || (isTest && !isTestEager)) &&
415
+ createCacheStrategy(mode)),
395
416
  };
396
417
 
397
418
  // Load and apply project-level overrides for the selected build