@modern-js/uni-builder 2.69.6 → 2.70.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.
@@ -36,6 +36,7 @@ var import_core = require("@rsbuild/core");
36
36
  var import_compatLegacyPlugin = require("../shared/compatLegacyPlugin");
37
37
  var import_parseCommonConfig = require("../shared/parseCommonConfig");
38
38
  var import_rsbuild_rsc_plugin = require("../shared/rsc/plugins/rsbuild-rsc-plugin");
39
+ var import_rscExternalFallback = require("../shared/rsc/rscExternalFallback");
39
40
  var import_utils = require("../shared/utils");
40
41
  async function parseConfig(uniBuilderConfig, options) {
41
42
  var _uniBuilderConfig_experiments, _uniBuilderConfig_tools, _uniBuilderConfig_tools1, _uniBuilderConfig_server;
@@ -139,6 +140,8 @@ async function parseConfig(uniBuilderConfig, options) {
139
140
  rscServerRuntimePath,
140
141
  internalDirectory
141
142
  }));
143
+ } else {
144
+ (0, import_rscExternalFallback.addRscExternalFallback)(rsbuildConfig, rsbuildPlugins);
142
145
  }
143
146
  return {
144
147
  rsbuildConfig,
@@ -45,6 +45,7 @@ const CSS_RULE_NAMES = [
45
45
  "scss",
46
46
  "sass"
47
47
  ];
48
+ const createVirtualModule = (content) => `data:text/javascript,${encodeURIComponent(content)}`;
48
49
  const checkReactVersionAtLeast19 = async (appDir) => {
49
50
  const packageJsonPath = import_node_path.default.resolve(appDir, "package.json");
50
51
  const packageJson = await import_fs_extra.default.readJSON(packageJsonPath);
@@ -154,6 +155,12 @@ const rsbuildRscPlugin = ({ appDir, isRspack = true, rscClientRuntimePath, rscSe
154
155
  chain.dependencies([
155
156
  "server"
156
157
  ]);
158
+ const entries = chain.entryPoints.entries();
159
+ for (const entryName of Object.keys(entries)) {
160
+ const entryPoint = chain.entry(entryName);
161
+ const code = `window.__MODERN_JS_ENTRY_NAME="${entryName}";`;
162
+ entryPoint.add(createVirtualModule(code));
163
+ }
157
164
  addRscClientLoader();
158
165
  addRscClientPlugin();
159
166
  }
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(rsc_client_plugin_exports);
24
24
  var import_common = require("../common");
25
25
  class RscClientPlugin {
26
26
  apply(compiler) {
27
- const { AsyncDependenciesBlock, RuntimeGlobals, WebpackError, dependencies: { ModuleDependency, NullDependency }, sources: { RawSource } } = compiler.webpack;
27
+ const { AsyncDependenciesBlock, WebpackError, dependencies: { ModuleDependency, NullDependency }, sources: { RawSource } } = compiler.webpack;
28
28
  const ssrManifest = {
29
29
  moduleMap: {},
30
30
  moduleLoading: null,
@@ -86,22 +86,6 @@ class RscClientPlugin {
86
86
  compiler.hooks.compilation.tap(RscClientPlugin.name, (compilation, { normalModuleFactory }) => {
87
87
  compilation.dependencyFactories.set(ClientReferenceDependency, normalModuleFactory);
88
88
  compilation.dependencyTemplates.set(ClientReferenceDependency, new NullDependency.Template());
89
- class EntryNameRuntimeModule extends compiler.webpack.RuntimeModule {
90
- generate() {
91
- return `window.__MODERN_JS_ENTRY_NAME="${this.entryName}";`;
92
- }
93
- constructor(entryName) {
94
- super("entry-name", 10);
95
- this.entryName = entryName;
96
- }
97
- }
98
- compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.ensureChunk).tap(RscClientPlugin.name, (chunk, set) => {
99
- Array.from(compilation.entrypoints.entries()).forEach(([entryName, entrypoint]) => {
100
- if (entrypoint.chunks.includes(chunk)) {
101
- compilation.addRuntimeModule(chunk, new EntryNameRuntimeModule(entryName));
102
- }
103
- });
104
- });
105
89
  });
106
90
  compiler.hooks.thisCompilation.tap(RscClientPlugin.name, (compilation, { normalModuleFactory }) => {
107
91
  this.styles = import_common.sharedData.get("styles");
@@ -120,8 +104,8 @@ class RscClientPlugin {
120
104
  normalModuleFactory.hooks.parser.for(`javascript/dynamic`).tap(`HarmonyModulesPlugin`, onNormalModuleFactoryParser);
121
105
  normalModuleFactory.hooks.parser.for(`javascript/esm`).tap(`HarmonyModulesPlugin`, onNormalModuleFactoryParser);
122
106
  compilation.hooks.additionalTreeRuntimeRequirements.tap(RscClientPlugin.name, (_chunk, runtimeRequirements) => {
123
- runtimeRequirements.add(RuntimeGlobals.ensureChunk);
124
- runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
107
+ runtimeRequirements.add(compiler.webpack.RuntimeGlobals.ensureChunk);
108
+ runtimeRequirements.add(compiler.webpack.RuntimeGlobals.compatGetDefaultExport);
125
109
  });
126
110
  compilation.hooks.processAssets.tap(RscClientPlugin.name, () => {
127
111
  const clientManifest = {};
@@ -38,7 +38,7 @@ const hasExtension = (filePath) => {
38
38
  };
39
39
  class RspackRscClientPlugin {
40
40
  apply(compiler) {
41
- const { EntryPlugin, RuntimeGlobals, RuntimeModule, WebpackError, sources: { RawSource } } = compiler.webpack;
41
+ const { EntryPlugin, RuntimeGlobals, WebpackError, sources: { RawSource } } = compiler.webpack;
42
42
  const ssrManifest = {
43
43
  moduleMap: {},
44
44
  moduleLoading: null,
@@ -122,24 +122,6 @@ class RspackRscClientPlugin {
122
122
  }
123
123
  }
124
124
  });
125
- compiler.hooks.compilation.tap(RspackRscClientPlugin.name, (compilation, { normalModuleFactory }) => {
126
- class EntryNameRuntimeModule extends RuntimeModule {
127
- generate() {
128
- return `window.__MODERN_JS_ENTRY_NAME="${this.entryName}";`;
129
- }
130
- constructor(entryName) {
131
- super("entry-name", 10);
132
- this.entryName = entryName;
133
- }
134
- }
135
- compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.ensureChunk).tap(RspackRscClientPlugin.name, (chunk, set) => {
136
- Array.from(compilation.entrypoints.entries()).forEach(([entryName, entrypoint]) => {
137
- if (entrypoint.chunks.includes(chunk)) {
138
- compilation.addRuntimeModule(chunk, new EntryNameRuntimeModule(entryName));
139
- }
140
- });
141
- });
142
- });
143
125
  compiler.hooks.thisCompilation.tap(RspackRscClientPlugin.name, (compilation, { normalModuleFactory }) => {
144
126
  this.styles = import_common.sharedData.get("styles");
145
127
  this.clientReferencesMap = import_common.sharedData.get("clientReferencesMap");
@@ -0,0 +1,7 @@
1
+ import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';
2
+ /**
3
+ * Add RSC external fallback when RSC is disabled.
4
+ * When RSC is disabled, provide an empty fallback for react-server-dom-webpack
5
+ * to avoid build errors while still allowing projects that may have conditional imports.
6
+ */
7
+ export declare function addRscExternalFallback(rsbuildConfig: RsbuildConfig, rsbuildPlugins: RsbuildPlugin[]): void;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var rscExternalFallback_exports = {};
20
+ __export(rscExternalFallback_exports, {
21
+ addRscExternalFallback: () => addRscExternalFallback
22
+ });
23
+ module.exports = __toCommonJS(rscExternalFallback_exports);
24
+ function addRscExternalFallback(rsbuildConfig, rsbuildPlugins) {
25
+ var _rsbuildConfig_output;
26
+ var _rsbuildConfig, _rsbuildConfig1, _rsbuildConfig_source;
27
+ const existingExternals = (_rsbuildConfig_output = rsbuildConfig.output) === null || _rsbuildConfig_output === void 0 ? void 0 : _rsbuildConfig_output.externals;
28
+ var _output;
29
+ (_output = (_rsbuildConfig = rsbuildConfig).output) !== null && _output !== void 0 ? _output : _rsbuildConfig.output = {};
30
+ const externalsArray = Array.isArray(existingExternals) ? existingExternals : existingExternals ? [
31
+ existingExternals
32
+ ] : [];
33
+ rsbuildConfig.output.externals = [
34
+ ...externalsArray,
35
+ {
36
+ "react-server-dom-webpack": "__REACT_SERVER_DOM_WEBPACK_EMPTY__"
37
+ }
38
+ ];
39
+ var _source;
40
+ (_source = (_rsbuildConfig1 = rsbuildConfig).source) !== null && _source !== void 0 ? _source : _rsbuildConfig1.source = {};
41
+ var _define;
42
+ (_define = (_rsbuildConfig_source = rsbuildConfig.source).define) !== null && _define !== void 0 ? _define : _rsbuildConfig_source.define = {};
43
+ if (!("__REACT_SERVER_DOM_WEBPACK_EMPTY__" in rsbuildConfig.source.define)) {
44
+ rsbuildConfig.source.define.__REACT_SERVER_DOM_WEBPACK_EMPTY__ = "{}";
45
+ }
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ addRscExternalFallback
50
+ });
@@ -37,6 +37,7 @@ var import_compatLegacyPlugin = require("../shared/compatLegacyPlugin");
37
37
  var import_parseCommonConfig = require("../shared/parseCommonConfig");
38
38
  var import_postcss = require("../shared/plugins/postcss");
39
39
  var import_rsbuild_rsc_plugin = require("../shared/rsc/plugins/rsbuild-rsc-plugin");
40
+ var import_rscExternalFallback = require("../shared/rsc/rscExternalFallback");
40
41
  var import_utils = require("../shared/utils");
41
42
  var import_babel = require("./plugins/babel");
42
43
  var import_include = require("./plugins/include");
@@ -109,6 +110,8 @@ async function parseConfig(uniBuilderConfig, options) {
109
110
  rscServerRuntimePath,
110
111
  internalDirectory
111
112
  }));
113
+ } else {
114
+ (0, import_rscExternalFallback.addRscExternalFallback)(rsbuildConfig, rsbuildPlugins);
112
115
  }
113
116
  if ((_uniBuilderConfig_tools1 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools1 === void 0 ? void 0 : _uniBuilderConfig_tools1.tsLoader) {
114
117
  const { pluginTsLoader } = await Promise.resolve().then(() => __toESM(require("./plugins/tsLoader")));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/uni-builder",
3
- "version": "2.69.6",
3
+ "version": "2.70.0",
4
4
  "description": "Unified builder for Modern.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  "@babel/preset-react": "^7.22.15",
41
41
  "@babel/types": "^7.26.0",
42
42
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.16",
43
- "@rsbuild/core": "1.6.15",
43
+ "@rsbuild/core": "1.7.2",
44
44
  "@rsbuild/plugin-assets-retry": "1.5.0",
45
45
  "@rsbuild/plugin-babel": "1.0.6",
46
46
  "@rsbuild/plugin-check-syntax": "1.6.0",
@@ -51,16 +51,16 @@
51
51
  "@rsbuild/plugin-rem": "1.0.4",
52
52
  "@rsbuild/plugin-sass": "1.4.0",
53
53
  "@rsbuild/plugin-source-build": "1.0.3",
54
- "@rsbuild/plugin-styled-components": "1.5.0",
54
+ "@rsbuild/plugin-styled-components": "1.6.0",
55
55
  "@rsbuild/plugin-svgr": "1.2.3",
56
56
  "@rsbuild/plugin-toml": "1.1.1",
57
57
  "@rsbuild/plugin-type-check": "1.3.2",
58
58
  "@rsbuild/plugin-typed-css-modules": "1.2.0",
59
59
  "@rsbuild/plugin-yaml": "1.0.3",
60
60
  "@rsbuild/webpack": "1.6.1",
61
- "@swc/core": "1.14.0",
61
+ "@swc/core": "1.15.8",
62
62
  "@swc/helpers": "^0.5.17",
63
- "autoprefixer": "10.4.21",
63
+ "autoprefixer": "10.4.23",
64
64
  "babel-loader": "9.2.1",
65
65
  "babel-plugin-import": "1.13.8",
66
66
  "babel-plugin-styled-components": "1.13.3",
@@ -70,7 +70,7 @@
70
70
  "es-module-lexer": "^1.1.0",
71
71
  "glob": "^9.3.5",
72
72
  "html-minifier-terser": "^7.2.0",
73
- "html-webpack-plugin": "5.6.4",
73
+ "html-webpack-plugin": "5.6.5",
74
74
  "jiti": "1.21.7",
75
75
  "lodash": "^4.17.21",
76
76
  "magic-string": "0.30.17",
@@ -90,9 +90,9 @@
90
90
  "ts-loader": "9.4.4",
91
91
  "webpack": "^5.103.0",
92
92
  "webpack-subresource-integrity": "5.1.0",
93
- "@modern-js/babel-preset": "2.69.6",
94
- "@modern-js/flight-server-transform-plugin": "2.69.6",
95
- "@modern-js/utils": "2.69.6"
93
+ "@modern-js/babel-preset": "2.70.0",
94
+ "@modern-js/flight-server-transform-plugin": "2.70.0",
95
+ "@modern-js/utils": "2.70.0"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@rsbuild/plugin-webpack-swc": "1.1.2",
@@ -103,9 +103,9 @@
103
103
  "react-dom": "^18.2.0",
104
104
  "terser": "^5.31.1",
105
105
  "typescript": "^5.3.0",
106
- "@modern-js/types": "2.69.6",
107
- "@scripts/vitest-config": "2.66.0",
108
- "@scripts/build": "2.66.0"
106
+ "@modern-js/types": "2.70.0",
107
+ "@scripts/build": "2.66.0",
108
+ "@scripts/vitest-config": "2.66.0"
109
109
  },
110
110
  "publishConfig": {
111
111
  "access": "public",