@nx/rspack 23.0.0-rc.4 → 23.1.0-beta.0

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.
Files changed (40) hide show
  1. package/README.md +1 -2
  2. package/dist/src/executors/rspack/lib/config.js +2 -2
  3. package/dist/src/executors/rspack/rspack.impl.js +3 -4
  4. package/dist/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +1 -1
  5. package/dist/src/generators/configuration/configuration.js +1 -3
  6. package/dist/src/migrations/update-23-0-0/migrate-rspack-config-to-v2.d.ts +5 -0
  7. package/dist/src/migrations/update-23-0-0/migrate-rspack-config-to-v2.js +163 -0
  8. package/dist/src/migrations/update-23-0-0/rewrite-experiments-css-to-module-rules.md +96 -0
  9. package/dist/src/plugins/generate-package-json-plugin.d.ts +1 -1
  10. package/dist/src/plugins/generate-package-json-plugin.js +5 -5
  11. package/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +2 -0
  12. package/dist/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +2 -1
  13. package/dist/src/plugins/utils/apply-base-config.d.ts +3 -2
  14. package/dist/src/plugins/utils/apply-base-config.js +56 -35
  15. package/dist/src/plugins/utils/apply-react-config.d.ts +13 -2
  16. package/dist/src/plugins/utils/apply-react-config.js +33 -7
  17. package/dist/src/plugins/utils/apply-web-config.d.ts +3 -2
  18. package/dist/src/plugins/utils/apply-web-config.js +23 -16
  19. package/dist/src/plugins/utils/loaders/stylesheet-loaders.d.ts +14 -14
  20. package/dist/src/plugins/utils/loaders/stylesheet-loaders.js +6 -7
  21. package/dist/src/plugins/utils/plugins/generate-package-json-plugin.d.ts +1 -1
  22. package/dist/src/plugins/utils/plugins/generate-package-json-plugin.js +5 -5
  23. package/dist/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.d.ts +1 -1
  24. package/dist/src/plugins/utils/plugins/scripts-rspack-plugin.d.ts +1 -1
  25. package/dist/src/plugins/utils/plugins/scripts-rspack-plugin.js +9 -8
  26. package/dist/src/plugins/utils/plugins/stats-json-plugin.d.ts +1 -1
  27. package/dist/src/plugins/utils/plugins/stats-json-plugin.js +2 -2
  28. package/dist/src/plugins/write-index-html-plugin.d.ts +1 -1
  29. package/dist/src/plugins/write-index-html-plugin.js +7 -8
  30. package/dist/src/utils/create-compiler.d.ts +1 -1
  31. package/dist/src/utils/is-serve-mode.d.ts +1 -0
  32. package/dist/src/utils/is-serve-mode.js +8 -0
  33. package/dist/src/utils/mode-utils.d.ts +1 -1
  34. package/dist/src/utils/read-rspack-options.d.ts +1 -1
  35. package/dist/src/utils/version-utils.d.ts +1 -17
  36. package/dist/src/utils/version-utils.js +6 -17
  37. package/dist/src/utils/versions.d.ts +1 -1
  38. package/dist/src/utils/versions.js +12 -8
  39. package/migrations.json +62 -0
  40. package/package.json +12 -12
@@ -1,20 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyReactConfig = applyReactConfig;
4
+ exports.applyReactConfigSync = applyReactConfigSync;
5
+ exports.applyReactHotReloadToCompiler = applyReactHotReloadToCompiler;
6
+ /**
7
+ * Apply rspack/react config for the compose path (e.g. `withReact`):
8
+ * sync tweaks + push react-refresh into `config.plugins`. Plugins that
9
+ * participate in rspack's lifecycle should call
10
+ * `applyReactConfigSync(...)` + `applyReactHotReloadToCompiler(...)`
11
+ * instead.
12
+ */
4
13
  function applyReactConfig(options = {}, config = {}) {
5
14
  if (global.NX_GRAPH_CREATION)
6
15
  return;
7
- addHotReload(config);
16
+ applyReactConfigSync(config);
17
+ if (isDevConfig(config)) {
18
+ const ReactRefreshPlugin = loadReactRefreshPluginClass();
19
+ config.plugins ??= [];
20
+ config.plugins.push(new ReactRefreshPlugin({ overlay: false }));
21
+ }
22
+ }
23
+ function applyReactConfigSync(config) {
8
24
  // enable rspack node api
9
25
  config.node = {
10
26
  __dirname: true,
11
27
  __filename: true,
12
28
  };
13
29
  }
14
- function addHotReload(config) {
15
- const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');
16
- const isDev = process.env.NODE_ENV === 'development' || config.mode === 'development';
17
- if (isDev) {
18
- config.plugins.push(new ReactRefreshPlugin({ overlay: false }));
19
- }
30
+ function applyReactHotReloadToCompiler(compiler) {
31
+ if (!isDevConfig(compiler.options))
32
+ return;
33
+ const ReactRefreshPlugin = loadReactRefreshPluginClass();
34
+ new ReactRefreshPlugin({ overlay: false }).apply(compiler);
35
+ }
36
+ function isDevConfig(config) {
37
+ return (process.env.NODE_ENV === 'development' || config.mode === 'development');
38
+ }
39
+ function loadReactRefreshPluginClass() {
40
+ // Lazy require — runs only when actually instantiated (CLI executor
41
+ // path; Jest never reaches this). Works on Node 22.12+ via require(esm).
42
+ // v1 (CJS) exports the class as default; v2 (ESM) only exports the named
43
+ // ReactRefreshRspackPlugin.
44
+ const mod = require('@rspack/plugin-react-refresh');
45
+ return mod.ReactRefreshRspackPlugin ?? mod.default ?? mod;
20
46
  }
@@ -1,5 +1,6 @@
1
- import { type Configuration, RspackOptionsNormalized } from '@rspack/core';
1
+ import type { Compiler, Configuration, RspackOptionsNormalized } from '@rspack/core';
2
2
  import { NormalizedNxAppRspackPluginOptions } from './models';
3
- export declare function applyWebConfig(options: NormalizedNxAppRspackPluginOptions, config?: Partial<RspackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
3
+ export declare function applyWebConfig(options: NormalizedNxAppRspackPluginOptions, config?: Partial<RspackOptionsNormalized | Configuration>, { useNormalizedEntry, compiler, }?: {
4
4
  useNormalizedEntry?: boolean;
5
+ compiler?: Compiler;
5
6
  }): void;
@@ -2,16 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyWebConfig = applyWebConfig;
4
4
  const internal_1 = require("@nx/js/internal");
5
- const core_1 = require("@rspack/core");
6
5
  const path_1 = require("path");
7
6
  const write_index_html_plugin_1 = require("../write-index-html-plugin");
8
7
  const hash_format_1 = require("./hash-format");
9
8
  const instantiate_script_plugins_1 = require("./instantiate-script-plugins");
10
9
  const stylesheet_loaders_1 = require("./loaders/stylesheet-loaders");
11
10
  const normalize_entry_1 = require("./normalize-entry");
12
- function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
11
+ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, } = {}) {
13
12
  if (global.NX_GRAPH_CREATION)
14
13
  return;
14
+ // Prefer compiler.rspack when available; otherwise lazy-require
15
+ // @rspack/core (works on Node 22.12+ via require(esm), and keeps the
16
+ // file Jest-loadable since the require is inside the function body).
17
+ const rspackCore = compiler
18
+ ? compiler.rspack
19
+ : require('@rspack/core');
20
+ const { CssExtractRspackPlugin, DefinePlugin, EnvironmentPlugin, HtmlRspackPlugin, LightningCssMinimizerRspackPlugin, } = rspackCore;
21
+ const cssExtractLoader = CssExtractRspackPlugin.loader;
15
22
  // Defaults that was applied from executor schema previously.
16
23
  options.runtimeChunk ??= true; // need this for HMR and other things to work
17
24
  options.extractCss ??= true;
@@ -23,7 +30,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
23
30
  options.scripts ??= [];
24
31
  const isProd = process.env.NODE_ENV === 'production' || options.mode === 'production';
25
32
  const plugins = [
26
- new core_1.EnvironmentPlugin({
33
+ new EnvironmentPlugin({
27
34
  NODE_ENV: isProd ? 'production' : 'development',
28
35
  }),
29
36
  ];
@@ -46,7 +53,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
46
53
  }));
47
54
  }
48
55
  else {
49
- plugins.push(new core_1.HtmlRspackPlugin({
56
+ plugins.push(new HtmlRspackPlugin({
50
57
  template: options.index,
51
58
  templateParameters: options.templateParameters,
52
59
  sri: options.subresourceIntegrity ? 'sha256' : undefined,
@@ -59,12 +66,12 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
59
66
  }
60
67
  const minimizer = [];
61
68
  if (isProd && stylesOptimization) {
62
- minimizer.push(new core_1.LightningCssMinimizerRspackPlugin({
69
+ minimizer.push(new LightningCssMinimizerRspackPlugin({
63
70
  test: /\.(?:css|scss|sass|less)$/,
64
71
  }));
65
72
  }
66
73
  if (!options.ssr) {
67
- plugins.push(new core_1.DefinePlugin(getClientEnvironment(process.env.NODE_ENV).stringified));
74
+ plugins.push(new DefinePlugin(getClientEnvironment(process.env.NODE_ENV).stringified));
68
75
  }
69
76
  const entries = {};
70
77
  const globalStylePaths = [];
@@ -96,13 +103,13 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
96
103
  {
97
104
  test: /\.module\.css$/,
98
105
  exclude: globalStylePaths,
99
- use: (0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
106
+ use: (0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader),
100
107
  },
101
108
  {
102
109
  test: /\.module\.(scss|sass)$/,
103
110
  exclude: globalStylePaths,
104
111
  use: [
105
- ...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
112
+ ...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader),
106
113
  {
107
114
  loader: require.resolve('sass-loader'),
108
115
  options: {
@@ -122,7 +129,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
122
129
  test: /\.module\.less$/,
123
130
  exclude: globalStylePaths,
124
131
  use: [
125
- ...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
132
+ ...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader),
126
133
  {
127
134
  loader: (0, path_1.join)(__dirname, 'loaders/deprecated-less-loader.js'),
128
135
  options: {
@@ -139,13 +146,13 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
139
146
  {
140
147
  test: /\.css$/,
141
148
  exclude: globalStylePaths,
142
- use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
149
+ use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader),
143
150
  },
144
151
  {
145
152
  test: /\.scss$|\.sass$/,
146
153
  exclude: globalStylePaths,
147
154
  use: [
148
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
155
+ ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader),
149
156
  {
150
157
  loader: require.resolve('sass-loader'),
151
158
  options: {
@@ -167,7 +174,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
167
174
  test: /\.less$/,
168
175
  exclude: globalStylePaths,
169
176
  use: [
170
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
177
+ ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader),
171
178
  {
172
179
  loader: (0, path_1.join)(__dirname, 'loaders/deprecated-less-loader.js'),
173
180
  options: {
@@ -186,13 +193,13 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
186
193
  {
187
194
  test: /\.css$/,
188
195
  include: globalStylePaths,
189
- use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
196
+ use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader),
190
197
  },
191
198
  {
192
199
  test: /\.scss$|\.sass$/,
193
200
  include: globalStylePaths,
194
201
  use: [
195
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
202
+ ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader),
196
203
  {
197
204
  loader: require.resolve('sass-loader'),
198
205
  options: {
@@ -214,7 +221,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
214
221
  test: /\.less$/,
215
222
  include: globalStylePaths,
216
223
  use: [
217
- ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
224
+ ...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader),
218
225
  {
219
226
  loader: (0, path_1.join)(__dirname, 'loaders/deprecated-less-loader.js'),
220
227
  options: {
@@ -238,7 +245,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
238
245
  if (options.extractCss) {
239
246
  plugins.push(
240
247
  // extract global css from js files into own css file
241
- new core_1.CssExtractRspackPlugin({
248
+ new CssExtractRspackPlugin({
242
249
  filename: config.output?.cssFilename ??
243
250
  (options.outputHashing
244
251
  ? `[name]${hashFormat.extract}.css`
@@ -3,7 +3,7 @@ interface PostcssOptions {
3
3
  (loader: any): any;
4
4
  config?: string;
5
5
  }
6
- export declare function getCommonLoadersForCssModules(options: any, includePaths: string[]): ({
6
+ export declare function getCommonLoadersForCssModules(options: any, includePaths: string[], cssExtractLoader: string): ({
7
7
  loader: string;
8
8
  options?: undefined;
9
9
  } | {
@@ -20,53 +20,53 @@ export declare function getCommonLoadersForCssModules(options: any, includePaths
20
20
  } | {
21
21
  loader: string;
22
22
  options: {
23
- implementation: any;
24
- postcssOptions: PostcssOptions;
25
23
  modules?: undefined;
26
24
  importLoaders?: undefined;
25
+ implementation: any;
26
+ postcssOptions: PostcssOptions;
27
27
  };
28
28
  })[];
29
- export declare function getCommonLoadersForGlobalCss(options: any, includePaths: string[]): ({
30
- loader: string;
29
+ export declare function getCommonLoadersForGlobalCss(options: any, includePaths: string[], cssExtractLoader: string): ({
31
30
  options?: undefined;
31
+ loader: string;
32
32
  } | {
33
33
  loader: string;
34
34
  options: {
35
- url: boolean;
36
35
  implementation?: undefined;
37
36
  postcssOptions?: undefined;
37
+ url: boolean;
38
38
  };
39
39
  } | {
40
40
  loader: string;
41
41
  options: {
42
+ url?: undefined;
42
43
  implementation: any;
43
44
  postcssOptions: PostcssOptions;
44
- url?: undefined;
45
45
  };
46
46
  })[];
47
- export declare function getCommonLoadersForGlobalStyle(options: any, includePaths: string[]): ({
47
+ export declare function getCommonLoadersForGlobalStyle(options: any, includePaths: string[], cssExtractLoader: string): ({
48
48
  loader: string;
49
49
  options: {
50
- esModule: boolean;
51
- url?: undefined;
52
50
  implementation?: undefined;
53
51
  postcssOptions?: undefined;
52
+ url?: undefined;
53
+ esModule: boolean;
54
54
  };
55
55
  } | {
56
56
  loader: string;
57
57
  options: {
58
- url: boolean;
59
- esModule?: undefined;
60
58
  implementation?: undefined;
61
59
  postcssOptions?: undefined;
60
+ esModule?: undefined;
61
+ url: boolean;
62
62
  };
63
63
  } | {
64
64
  loader: string;
65
65
  options: {
66
+ url?: undefined;
67
+ esModule?: undefined;
66
68
  implementation: any;
67
69
  postcssOptions: PostcssOptions;
68
- esModule?: undefined;
69
- url?: undefined;
70
70
  };
71
71
  })[];
72
72
  export {};
@@ -7,16 +7,15 @@ const tslib_1 = require("tslib");
7
7
  const path = tslib_1.__importStar(require("path"));
8
8
  const autoprefixer = require("autoprefixer");
9
9
  const postcssImports = require("postcss-import");
10
- const core_1 = require("@rspack/core");
11
10
  const get_css_module_local_ident_1 = require("../get-css-module-local-ident");
12
11
  const hash_format_1 = require("../hash-format");
13
12
  const postcss_cli_resources_1 = require("../plugins/postcss-cli-resources");
14
- function getCommonLoadersForCssModules(options, includePaths) {
13
+ function getCommonLoadersForCssModules(options, includePaths, cssExtractLoader) {
15
14
  // load component css as raw strings
16
15
  return [
17
16
  {
18
17
  loader: options.extractCss
19
- ? core_1.CssExtractRspackPlugin.loader
18
+ ? cssExtractLoader
20
19
  : require.resolve('style-loader'),
21
20
  },
22
21
  {
@@ -41,11 +40,11 @@ function getCommonLoadersForCssModules(options, includePaths) {
41
40
  },
42
41
  ];
43
42
  }
44
- function getCommonLoadersForGlobalCss(options, includePaths) {
43
+ function getCommonLoadersForGlobalCss(options, includePaths, cssExtractLoader) {
45
44
  return [
46
45
  {
47
46
  loader: options.extractCss
48
- ? core_1.CssExtractRspackPlugin.loader
47
+ ? cssExtractLoader
49
48
  : require.resolve('style-loader'),
50
49
  },
51
50
  { loader: require.resolve('css-loader'), options: { url: false } },
@@ -60,11 +59,11 @@ function getCommonLoadersForGlobalCss(options, includePaths) {
60
59
  },
61
60
  ];
62
61
  }
63
- function getCommonLoadersForGlobalStyle(options, includePaths) {
62
+ function getCommonLoadersForGlobalStyle(options, includePaths, cssExtractLoader) {
64
63
  return [
65
64
  {
66
65
  loader: options.extractCss
67
- ? core_1.CssExtractRspackPlugin.loader
66
+ ? cssExtractLoader
68
67
  : require.resolve('style-loader'),
69
68
  options: { esModule: true },
70
69
  },
@@ -1,4 +1,4 @@
1
- import { type Compiler, type RspackPluginInstance } from '@rspack/core';
1
+ import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
2
  import { type ProjectGraph } from '@nx/devkit';
3
3
  export declare class GeneratePackageJsonPlugin implements RspackPluginInstance {
4
4
  private readonly options;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GeneratePackageJsonPlugin = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs"));
6
- const core_1 = require("@rspack/core");
7
6
  const js_1 = require("@nx/js");
8
7
  const devkit_1 = require("@nx/devkit");
9
8
  const pluginName = 'GeneratePackageJsonPlugin';
@@ -26,10 +25,11 @@ class GeneratePackageJsonPlugin {
26
25
  }
27
26
  apply(compiler) {
28
27
  compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
29
- compilation.hooks.processAssets.tap({
28
+ compilation.hooks.processAssets.tapPromise({
30
29
  name: pluginName,
31
30
  stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
32
- }, () => {
31
+ }, async () => {
32
+ const sources = compiler.rspack.sources;
33
33
  const helperDependencies = (0, js_1.getHelperDependenciesFromProjectGraph)(this.options.root, this.options.projectName, this.options.projectGraph);
34
34
  const importHelpers = !!(0, js_1.readTsConfig)(this.options.tsConfig).options
35
35
  .importHelpers;
@@ -55,7 +55,7 @@ class GeneratePackageJsonPlugin {
55
55
  ...packageJson.dependencies,
56
56
  ...runtimeDependencies,
57
57
  };
58
- compilation.emitAsset('package.json', new core_1.sources.RawSource((0, devkit_1.serializeJson)(packageJson)));
58
+ compilation.emitAsset('package.json', new sources.RawSource((0, devkit_1.serializeJson)(packageJson)));
59
59
  const packageManager = (0, devkit_1.detectPackageManager)(this.options.root);
60
60
  if (packageManager === 'bun') {
61
61
  compilation
@@ -63,7 +63,7 @@ class GeneratePackageJsonPlugin {
63
63
  .warn('Bun lockfile generation is not supported. Only package.json will be generated.');
64
64
  }
65
65
  else {
66
- compilation.emitAsset((0, js_1.getLockFileName)(packageManager), new core_1.sources.RawSource((0, js_1.createLockFile)(packageJson, this.options.projectGraph, packageManager)));
66
+ compilation.emitAsset((0, js_1.getLockFileName)(packageManager), new sources.RawSource((0, js_1.createLockFile)(packageJson, this.options.projectGraph, packageManager)));
67
67
  }
68
68
  });
69
69
  });
@@ -1,4 +1,4 @@
1
- import { Compiler, type Configuration, type RspackOptionsNormalized } from '@rspack/core';
1
+ import type { Compiler, Configuration, RspackOptionsNormalized } from '@rspack/core';
2
2
  import { NormalizedNxAppRspackPluginOptions } from '../models';
3
3
  export declare class NxTsconfigPathsRspackPlugin {
4
4
  private options;
@@ -1,4 +1,4 @@
1
- import { type Compiler } from '@rspack/core';
1
+ import type { Compiler } from '@rspack/core';
2
2
  export interface ScriptsRspackPluginOptions {
3
3
  name: string;
4
4
  sourceMap: boolean;
@@ -4,7 +4,6 @@ exports.ScriptsRspackPlugin = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const loader_utils_1 = require("loader-utils");
6
6
  const path = tslib_1.__importStar(require("path"));
7
- const core_1 = require("@rspack/core");
8
7
  function addDependencies(compilation, scripts) {
9
8
  for (const script of scripts) {
10
9
  compilation.fileDependencies.add(script);
@@ -19,8 +18,8 @@ class ScriptsRspackPlugin {
19
18
  constructor(options = {}) {
20
19
  this.options = options;
21
20
  }
22
- _insertOutput(compiler, compilation, { filename, source }, cached = false) {
23
- new core_1.EntryPlugin(compiler.context, this.options.name).apply(compiler);
21
+ _insertOutput(compiler, compilation, { filename, source }, EntryPluginCtor, cached = false) {
22
+ new EntryPluginCtor(compiler.context, this.options.name).apply(compiler);
24
23
  compilation.assets[filename] = source;
25
24
  }
26
25
  apply(compiler) {
@@ -31,6 +30,8 @@ class ScriptsRspackPlugin {
31
30
  .filter((script) => !!script)
32
31
  .map((script) => path.resolve(this.options.basePath || '', script));
33
32
  hook(compiler, (compilation, callback) => {
33
+ const rspackSources = compiler.rspack.sources;
34
+ const EntryPluginCtor = compiler.rspack.EntryPlugin;
34
35
  const sourceGetters = scripts.map((fullPath) => {
35
36
  return new Promise((resolve, reject) => {
36
37
  compilation.inputFileSystem.readFile(fullPath, (err, data) => {
@@ -46,10 +47,10 @@ class ScriptsRspackPlugin {
46
47
  if (this.options.basePath) {
47
48
  adjustedPath = path.relative(this.options.basePath, fullPath);
48
49
  }
49
- source = new core_1.sources.OriginalSource(content, adjustedPath);
50
+ source = new rspackSources.OriginalSource(content, adjustedPath);
50
51
  }
51
52
  else {
52
- source = new core_1.sources.RawSource(content);
53
+ source = new rspackSources.RawSource(content);
53
54
  }
54
55
  resolve(source);
55
56
  });
@@ -57,15 +58,15 @@ class ScriptsRspackPlugin {
57
58
  });
58
59
  Promise.all(sourceGetters)
59
60
  .then((_sources) => {
60
- const concatSource = new core_1.sources.ConcatSource();
61
+ const concatSource = new rspackSources.ConcatSource();
61
62
  _sources.forEach((source) => {
62
63
  concatSource.add(source);
63
64
  concatSource.add('\n;');
64
65
  });
65
- const combinedSource = new core_1.sources.CachedSource(concatSource);
66
+ const combinedSource = new rspackSources.CachedSource(concatSource);
66
67
  const filename = (0, loader_utils_1.interpolateName)({ resourcePath: 'scripts.js' }, this.options.filename, { content: combinedSource.source() });
67
68
  const output = { filename, source: combinedSource };
68
- this._insertOutput(compiler, compilation, output);
69
+ this._insertOutput(compiler, compilation, output, EntryPluginCtor);
69
70
  this._cachedOutput = output;
70
71
  addDependencies(compilation, scripts);
71
72
  callback();
@@ -1,4 +1,4 @@
1
- import { Compiler } from '@rspack/core';
1
+ import type { Compiler } from '@rspack/core';
2
2
  export declare class StatsJsonPlugin {
3
3
  apply(compiler: Compiler): void;
4
4
  }
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StatsJsonPlugin = void 0;
4
- const core_1 = require("@rspack/core");
5
4
  class StatsJsonPlugin {
6
5
  apply(compiler) {
7
6
  compiler.hooks.emit.tap('StatsJsonPlugin', (compilation) => {
7
+ const sources = compiler.rspack.sources;
8
8
  const data = JSON.stringify(compilation.getStats().toJson('verbose'));
9
- compilation.assets[`stats.json`] = new core_1.sources.RawSource(data);
9
+ compilation.assets[`stats.json`] = new sources.RawSource(data);
10
10
  });
11
11
  }
12
12
  }
@@ -1,4 +1,4 @@
1
- import { Compiler } from '@rspack/core';
1
+ import type { Compiler } from '@rspack/core';
2
2
  import { ExtraEntryPoint } from '../utils/model';
3
3
  export interface WriteIndexHtmlOptions {
4
4
  indexPath: string;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WriteIndexHtmlPlugin = void 0;
4
- const tslib_1 = require("tslib");
5
- const rspack = tslib_1.__importStar(require("@rspack/core"));
6
4
  const crypto_1 = require("crypto");
7
5
  const fs_1 = require("fs");
8
6
  const interpolate_env_variables_to_index_1 = require("../utils/webpack/interpolate-env-variables-to-index");
@@ -16,11 +14,12 @@ class WriteIndexHtmlPlugin {
16
14
  apply(compiler) {
17
15
  const { outputPath, indexPath, baseHref, deployUrl, sri = false, scripts = [], styles = [], crossOrigin, } = this.options;
18
16
  compiler.hooks.thisCompilation.tap('WriteIndexHtmlPlugin', (compilation) => {
19
- compilation.hooks.processAssets.tap({
17
+ compilation.hooks.processAssets.tapPromise({
20
18
  name: 'WriteIndexHtmlPlugin',
21
19
  // After minification and sourcemaps are done
22
- stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
23
- }, () => {
20
+ stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
21
+ }, async () => {
22
+ const sources = compiler.rspack.sources;
24
23
  const moduleFiles = this.getEmittedFiles(compilation);
25
24
  const files = moduleFiles.filter((x) => x.extension === '.css');
26
25
  let content = (0, fs_1.readFileSync)(indexPath).toString();
@@ -36,7 +35,7 @@ class WriteIndexHtmlPlugin {
36
35
  files: this.filterAndMapBuildFiles(files, ['.js', '.css']),
37
36
  moduleFiles: this.filterAndMapBuildFiles(moduleFiles, ['.js']),
38
37
  loadOutputFile: (filePath) => compilation.assets[filePath].source().toString(),
39
- });
38
+ }, sources);
40
39
  });
41
40
  });
42
41
  }
@@ -70,7 +69,7 @@ class WriteIndexHtmlPlugin {
70
69
  stripBom(data) {
71
70
  return data.replace(/^\uFEFF/, '');
72
71
  }
73
- augmentIndexHtml(params) {
72
+ augmentIndexHtml(params, sources) {
74
73
  const { loadOutputFile, files, moduleFiles = [], entrypoints } = params;
75
74
  let { crossOrigin = 'none' } = params;
76
75
  if (params.sri && crossOrigin === 'none') {
@@ -138,7 +137,7 @@ class WriteIndexHtmlPlugin {
138
137
  styleInsertionPoint = params.inputContent.indexOf('</head>');
139
138
  }
140
139
  // Inject into the html
141
- const indexSource = new rspack.sources.ReplaceSource(new rspack.sources.RawSource(params.inputContent), params.input);
140
+ const indexSource = new sources.ReplaceSource(new sources.RawSource(params.inputContent), params.input);
142
141
  let scriptElements = '';
143
142
  for (const script of scripts) {
144
143
  const attrs = [
@@ -1,5 +1,5 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
- import { Compiler, MultiCompiler } from '@rspack/core';
2
+ import { type Compiler, type MultiCompiler } from '@rspack/core';
3
3
  import { NormalizedRspackExecutorSchema } from '../executors/rspack/schema';
4
4
  export declare function createCompiler(options: NormalizedRspackExecutorSchema & {
5
5
  devServer?: any;
@@ -0,0 +1 @@
1
+ export declare function isServeMode(): boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isServeMode = isServeMode;
4
+ // v1 dev-server sets WEBPACK_SERVE on module load; v2 sets RSPACK_SERVE.
5
+ // rspack-cli imports the dev-server before loading the user config.
6
+ function isServeMode() {
7
+ return !!process.env['WEBPACK_SERVE'] || !!process.env['RSPACK_SERVE'];
8
+ }
@@ -1,2 +1,2 @@
1
- import { Mode } from '@rspack/core';
1
+ import type { Mode } from '@rspack/core';
2
2
  export declare function isMode(mode: string): mode is Mode;
@@ -1,4 +1,4 @@
1
- import { Configuration } from '@rspack/core';
1
+ import type { Configuration } from '@rspack/core';
2
2
  /**
3
3
  * Reads the Rspack options from a give Rspack configuration. The configuration can be:
4
4
  * 1. A single standard config object
@@ -1,24 +1,8 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  import { type SupportedRspackMajorVersion } from './versions';
3
- /**
4
- * Returns the declared @rspack/core major version from the workspace's
5
- * package.json when it matches a supported major, or `undefined` otherwise
6
- * (fresh install, dist tag, unknown major). Below-floor enforcement is
7
- * handled at generator entry points via `assertSupportedRspackVersion`.
8
- */
9
3
  export declare function getInstalledRspackMajorVersion(tree: Tree): SupportedRspackMajorVersion | undefined;
10
- /**
11
- * Returns the installed @rspack/core major version resolved at runtime from
12
- * node_modules. For use in executors and runtime code where no Tree is
13
- * available. Returns `null` when @rspack/core can't be resolved or the
14
- * installed major isn't supported.
15
- */
16
4
  export declare function getInstalledRspackVersionRuntime(): SupportedRspackMajorVersion | null;
17
- /**
18
- * Returns the version-map entry for the installed major, falling back to the
19
- * latest supported map when no installed version is detected (fresh install)
20
- * or the detected major is outside the supported window.
21
- */
5
+ export declare function getRspackCoreMajorVersion(rspackCore: typeof import('@rspack/core')): number;
22
6
  export declare function getRspackVersionsForInstalledMajor(tree: Tree): {
23
7
  rspackCoreVersion: string;
24
8
  rspackDevServerVersion: string;
@@ -2,17 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInstalledRspackMajorVersion = getInstalledRspackMajorVersion;
4
4
  exports.getInstalledRspackVersionRuntime = getInstalledRspackVersionRuntime;
5
+ exports.getRspackCoreMajorVersion = getRspackCoreMajorVersion;
5
6
  exports.getRspackVersionsForInstalledMajor = getRspackVersionsForInstalledMajor;
6
7
  const internal_1 = require("@nx/devkit/internal");
7
8
  const semver_1 = require("semver");
8
9
  const versions_1 = require("./versions");
9
10
  const RSPACK_CORE_PACKAGE = '@rspack/core';
10
- /**
11
- * Returns the declared @rspack/core major version from the workspace's
12
- * package.json when it matches a supported major, or `undefined` otherwise
13
- * (fresh install, dist tag, unknown major). Below-floor enforcement is
14
- * handled at generator entry points via `assertSupportedRspackVersion`.
15
- */
16
11
  function getInstalledRspackMajorVersion(tree) {
17
12
  const declared = (0, internal_1.getDeclaredPackageVersion)(tree, RSPACK_CORE_PACKAGE);
18
13
  if (!declared) {
@@ -23,12 +18,6 @@ function getInstalledRspackMajorVersion(tree) {
23
18
  ? installedMajor
24
19
  : undefined;
25
20
  }
26
- /**
27
- * Returns the installed @rspack/core major version resolved at runtime from
28
- * node_modules. For use in executors and runtime code where no Tree is
29
- * available. Returns `null` when @rspack/core can't be resolved or the
30
- * installed major isn't supported.
31
- */
32
21
  function getInstalledRspackVersionRuntime() {
33
22
  const version = (0, internal_1.getInstalledPackageVersion)(RSPACK_CORE_PACKAGE);
34
23
  if (!version) {
@@ -39,11 +28,11 @@ function getInstalledRspackVersionRuntime() {
39
28
  ? installedMajor
40
29
  : null;
41
30
  }
42
- /**
43
- * Returns the version-map entry for the installed major, falling back to the
44
- * latest supported map when no installed version is detected (fresh install)
45
- * or the detected major is outside the supported window.
46
- */
31
+ // Reads the version off an already-resolved `@rspack/core` module instance
32
+ // (e.g. `compiler.rspack`) avoids a second resolution at runtime.
33
+ function getRspackCoreMajorVersion(rspackCore) {
34
+ return (0, semver_1.major)(rspackCore.rspackVersion ?? '1.0.0');
35
+ }
47
36
  function getRspackVersionsForInstalledMajor(tree) {
48
37
  const installed = getInstalledRspackMajorVersion(tree);
49
38
  if (installed === undefined) {
@@ -4,7 +4,7 @@ export declare const lessLoaderVersion = "~11.1.3";
4
4
  export declare const sassLoaderVersion = "^16.0.7";
5
5
  export declare const sassEmbeddedVersion = "^1.97.2";
6
6
  export declare const reactRefreshVersion = "~0.14.0";
7
- export declare const supportedRspackMajorVersions: readonly [1];
7
+ export declare const supportedRspackMajorVersions: readonly [2, 1];
8
8
  export type SupportedRspackMajorVersion = (typeof supportedRspackMajorVersions)[number];
9
9
  type RspackVersionMap = {
10
10
  rspackCoreVersion: string;