@meteorjs/rspack 0.0.24 → 0.0.26

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,11 @@
1
+ {
2
+ console.log("--> (eager-app-tests.js-Line: 8)\n entro: ");
3
+ const ctx = import.meta.webpackContext('/', {
4
+ recursive: true,
5
+ regExp: /\.app-(?:test|spec)s?\.[^.]+$/,
6
+ exclude: /(^|\/)(node_modules|\.meteor|_build)(\/|$)/,
7
+ mode: 'eager',
8
+ });
9
+ console.log("--> (eager-app-tests.js-Line: 8)\n ctx: ", ctx);
10
+ ctx.keys().forEach(ctx);
11
+ }
@@ -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.26",
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(),
@@ -114,15 +120,16 @@ export default function (inMeteor = {}, argv = {}) {
114
120
  }
115
121
  }
116
122
 
117
- const isProd = Meteor.isProduction || argv.mode === 'production';
118
- const isDev = Meteor.isDevelopment || !isProd;
119
- const isTest = Meteor.isTest;
120
- const isClient = Meteor.isClient;
121
- const isRun = Meteor.isRun;
122
- const isReactEnabled = Meteor.isReactEnabled;
123
- const isTestModule = Meteor.isTestModule;
124
- const isTestEager = Meteor.isTestEager;
125
- const swcExternalHelpers = Meteor.swcExternalHelpers;
123
+ const isProd = !!Meteor.isProduction || argv.mode === 'production';
124
+ const isDev = !!Meteor.isDevelopment || !isProd;
125
+ const isTest = !!Meteor.isTest;
126
+ const isClient = !!Meteor.isClient;
127
+ const isRun = !!Meteor.isRun;
128
+ const isReactEnabled = !!Meteor.isReactEnabled;
129
+ const isTestModule = !!Meteor.isTestModule;
130
+ const isTestEager = !!Meteor.isTestEager;
131
+ const isTestFullApp = !!Meteor.isTestFullApp;
132
+ const swcExternalHelpers = !!Meteor.swcExternalHelpers;
126
133
  const mode = isProd ? 'production' : 'development';
127
134
 
128
135
  const isTypescriptEnabled = Meteor.isTypescriptEnabled || false;
@@ -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,21 +349,28 @@ 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
+ ? path.resolve(process.cwd(), 'node_modules/@meteorjs/rspack/entries/eager-app-tests.js')
355
+ : isTest && isTestEager
356
+ ? path.resolve(process.cwd(), '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}`,
348
370
  libraryTarget: 'commonjs',
349
- chunkFilename: `${bundlesContext}/[id].[chunkhash].js`,
371
+ chunkFilename: `${bundlesContext}/[id]${isProd ? '.[chunkhash]' : ''}.js`,
350
372
  assetModuleFilename: `${assetsContext}/[hash][ext][query]`,
373
+ clean: isProd,
351
374
  },
352
375
  optimization: { usedExports: true },
353
376
  module: {
@@ -370,16 +393,16 @@ export default function (inMeteor = {}, argv = {}) {
370
393
  new DefinePlugin(
371
394
  isTest && (isTestModule || isTestEager)
372
395
  ? {
373
- "Meteor.isTest": JSON.stringify(isTest),
374
- "Meteor.isDevelopment": JSON.stringify(isDev),
396
+ 'Meteor.isTest': JSON.stringify(isTest),
397
+ 'Meteor.isDevelopment': JSON.stringify(isDev),
375
398
  }
376
399
  : {
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
- }
400
+ 'Meteor.isClient': JSON.stringify(false),
401
+ 'Meteor.isServer': JSON.stringify(true),
402
+ 'Meteor.isTest': JSON.stringify(isTest),
403
+ 'Meteor.isDevelopment': JSON.stringify(isDev),
404
+ 'Meteor.isProduction': JSON.stringify(isProd),
405
+ },
383
406
  ),
384
407
  new BannerPlugin({
385
408
  banner: bannerOutput,
@@ -389,9 +412,8 @@ export default function (inMeteor = {}, argv = {}) {
389
412
  ],
390
413
  watchOptions,
391
414
  devtool: isDevEnvironment || isTest ? 'source-map' : 'hidden-source-map',
392
- ...((isDevEnvironment || isTest && !isTestEager) &&
393
- createCacheStrategy(mode)
394
- ),
415
+ ...((isDevEnvironment || (isTest && !isTestEager)) &&
416
+ createCacheStrategy(mode)),
395
417
  };
396
418
 
397
419
  // Load and apply project-level overrides for the selected build