@modern-js/builder 3.0.0-alpha.0 → 3.0.0-alpha.1

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.
@@ -129,7 +129,7 @@ async function parseConfig(builderConfig, options) {
129
129
  };
130
130
  }
131
131
  async function createRspackBuilder(options) {
132
- const { cwd = process.cwd(), config, rscClientRuntimePath, rscServerRuntimePath, ...rest } = options;
132
+ const { cwd = process.cwd(), config, ...rest } = options;
133
133
  const { rsbuildConfig, rsbuildPlugins } = await parseConfig(config, {
134
134
  ...rest,
135
135
  cwd
@@ -43,6 +43,7 @@ const CSS_RULE_NAMES = [
43
43
  "scss",
44
44
  "sass"
45
45
  ];
46
+ const createVirtualModule = (content) => `data:text/javascript,${encodeURIComponent(content)}`;
46
47
  const checkReactVersionAtLeast19 = async (appDir) => {
47
48
  const packageJsonPath = import_node_path.default.resolve(appDir, "package.json");
48
49
  const packageJson = await import_fs_extra.default.readJSON(packageJsonPath);
@@ -69,7 +70,7 @@ const rsbuildRscPlugin = ({ appDir, rscClientRuntimePath, rscServerRuntimePath,
69
70
  name: "builder:rsc-rsbuild-plugin",
70
71
  setup(api) {
71
72
  api.modifyBundlerChain({
72
- handler: async (chain, { isServer, CHAIN_ID }) => {
73
+ handler: async (chain, { isServer, CHAIN_ID, isWebWorker }) => {
73
74
  if (!await checkReactVersionAtLeast19(appDir)) {
74
75
  import_core.logger.error("Enable react server component, please make sure the react and react-dom versions are greater than or equal to 19.0.0");
75
76
  process.exit(1);
@@ -147,11 +148,17 @@ const rsbuildRscPlugin = ({ appDir, rscClientRuntimePath, rscServerRuntimePath,
147
148
  flightCssHandler();
148
149
  jsHandler();
149
150
  addServerRscPlugin();
150
- } else {
151
+ } else if (!isWebWorker) {
151
152
  chain.name("client");
152
153
  chain.dependencies([
153
154
  "server"
154
155
  ]);
156
+ const entries = chain.entryPoints.entries();
157
+ for (const entryName of Object.keys(entries)) {
158
+ const entryPoint = chain.entry(entryName);
159
+ const code = `window.__MODERN_JS_ENTRY_NAME="${entryName}";`;
160
+ entryPoint.add(createVirtualModule(code));
161
+ }
155
162
  addRscClientLoader();
156
163
  addRscClientPlugin();
157
164
  }
@@ -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.rspack;
41
+ const { EntryPlugin, RuntimeGlobals, WebpackError, sources: { RawSource } } = compiler.rspack;
42
42
  const ssrManifest = {
43
43
  moduleMap: {},
44
44
  moduleLoading: null,
@@ -118,24 +118,6 @@ class RspackRscClientPlugin {
118
118
  }
119
119
  }
120
120
  });
121
- compiler.hooks.compilation.tap(RspackRscClientPlugin.name, (compilation) => {
122
- class EntryNameRuntimeModule extends RuntimeModule {
123
- generate() {
124
- return `window.__MODERN_JS_ENTRY_NAME="${this.entryName}";`;
125
- }
126
- constructor(entryName) {
127
- super("entry-name", 10);
128
- this.entryName = entryName;
129
- }
130
- }
131
- compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.ensureChunk).tap(RspackRscClientPlugin.name, (chunk) => {
132
- Array.from(compilation.entrypoints.entries()).forEach(([entryName, entrypoint]) => {
133
- if (entrypoint.chunks.includes(chunk)) {
134
- compilation.addRuntimeModule(chunk, new EntryNameRuntimeModule(entryName));
135
- }
136
- });
137
- });
138
- });
139
121
  compiler.hooks.thisCompilation.tap(RspackRscClientPlugin.name, (compilation) => {
140
122
  this.styles = import_common.sharedData.get("styles");
141
123
  this.clientReferencesMap = import_common.sharedData.get("clientReferencesMap");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/builder",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.1",
4
4
  "description": "A builder for Modern.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@rsbuild/core": "1.6.15",
25
+ "@rsbuild/core": "1.7.1",
26
26
  "@rsbuild/plugin-assets-retry": "1.5.0",
27
27
  "@rsbuild/plugin-babel": "1.0.6",
28
28
  "@rsbuild/plugin-check-syntax": "1.6.0",
@@ -35,7 +35,7 @@
35
35
  "@rsbuild/plugin-svgr": "1.2.3",
36
36
  "@rsbuild/plugin-type-check": "1.3.2",
37
37
  "@rsbuild/plugin-typed-css-modules": "1.2.0",
38
- "@swc/core": "1.14.0",
38
+ "@swc/core": "1.15.8",
39
39
  "@swc/helpers": "^0.5.17",
40
40
  "autoprefixer": "10.4.23",
41
41
  "browserslist": "4.28.1",
@@ -51,10 +51,10 @@
51
51
  "postcss-media-minmax": "5.0.0",
52
52
  "postcss-nesting": "12.1.5",
53
53
  "postcss-page-break": "3.0.4",
54
- "rspack-manifest-plugin": "5.1.0",
54
+ "rspack-manifest-plugin": "5.2.0",
55
55
  "ts-deepmerge": "7.0.3",
56
- "@modern-js/flight-server-transform-plugin": "3.0.0-alpha.0",
57
- "@modern-js/utils": "3.0.0-alpha.0"
56
+ "@modern-js/flight-server-transform-plugin": "3.0.0-alpha.1",
57
+ "@modern-js/utils": "3.0.0-alpha.1"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/html-minifier-terser": "^7.0.2",
@@ -62,9 +62,9 @@
62
62
  "react": "^19.2.3",
63
63
  "terser": "^5.44.1",
64
64
  "typescript": "^5.3.0",
65
- "@modern-js/types": "3.0.0-alpha.0",
66
- "@scripts/rstest-config": "2.66.0",
67
- "@scripts/build": "2.66.0"
65
+ "@modern-js/types": "3.0.0-alpha.1",
66
+ "@scripts/build": "2.66.0",
67
+ "@scripts/rstest-config": "2.66.0"
68
68
  },
69
69
  "publishConfig": {
70
70
  "access": "public",