From 8247b7d4e7afa714f143adad2c85529faa0d085a Mon Sep 17 00:00:00 2001 From: Ming Date: Wed, 11 Sep 2024 15:32:13 +0800 Subject: [PATCH 1/2] docs: remove the tip that rspack is not yet supported (#6208) --- .../document/main-doc/docs/en/guides/basic-features/routes.mdx | 3 +-- .../document/main-doc/docs/zh/guides/basic-features/routes.mdx | 3 +-- .../runtime/plugin-runtime/src/router/runtime/PrefetchLink.tsx | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/document/main-doc/docs/en/guides/basic-features/routes.mdx b/packages/document/main-doc/docs/en/guides/basic-features/routes.mdx index ca9be169552d..5c930a9310c1 100644 --- a/packages/document/main-doc/docs/en/guides/basic-features/routes.mdx +++ b/packages/document/main-doc/docs/en/guides/basic-features/routes.mdx @@ -462,8 +462,7 @@ For applications with higher performance requirements, prefetching can further e :::tip -- This feature is currently only supported in Webpack projects and not in Rspack projects. -- Data preloading currently only preloads data returned by the [Data Loader](/guides/basic-features/data/data-fetch) in SSR projects. +Data preloading currently only preloads data returned by the [Data Loader](/guides/basic-features/data/data-fetch) in SSR projects. ::: diff --git a/packages/document/main-doc/docs/zh/guides/basic-features/routes.mdx b/packages/document/main-doc/docs/zh/guides/basic-features/routes.mdx index f18454651614..d577da7a3c12 100644 --- a/packages/document/main-doc/docs/zh/guides/basic-features/routes.mdx +++ b/packages/document/main-doc/docs/zh/guides/basic-features/routes.mdx @@ -464,8 +464,7 @@ Modern.js 支持通过 `loading.tsx` 文件来解决这个问题,`routes/` 下 :::tip -- 该功能目前仅在 Webpack 项目中支持,Rspack 项目暂不支持。 -- 对数据的预加载目前只会预加载 SSR 项目中 [Data Loader](/guides/basic-features/data/data-fetch) 中返回的数据。 +对数据的预加载目前只会预加载 SSR 项目中 [Data Loader](/guides/basic-features/data/data-fetch) 中返回的数据。 ::: diff --git a/packages/runtime/plugin-runtime/src/router/runtime/PrefetchLink.tsx b/packages/runtime/plugin-runtime/src/router/runtime/PrefetchLink.tsx index 1b865d405ec9..a29cf94f48b9 100644 --- a/packages/runtime/plugin-runtime/src/router/runtime/PrefetchLink.tsx +++ b/packages/runtime/plugin-runtime/src/router/runtime/PrefetchLink.tsx @@ -27,7 +27,6 @@ interface PrefetchHandlers { onTouchStart?: TouchEventHandler; } -// TODO: 支持 rspack declare const __webpack_chunk_load__: | ((chunkId: string | number) => Promise) | undefined; From 4f19e98291bd11029f11c8f17087d63f92de36d4 Mon Sep 17 00:00:00 2001 From: 9aoy Date: Wed, 11 Sep 2024 16:20:03 +0800 Subject: [PATCH 2/2] chore: rename serviceWorker environment name to workerSSR (#6210) --- .changeset/hot-jobs-occur.md | 6 ++++++ .../uni-builder/src/shared/plugins/environmentDefaults.ts | 2 +- packages/cli/uni-builder/src/shared/utils.ts | 2 +- .../uni-builder/tests/__snapshots__/default.test.ts.snap | 4 ++-- .../tests/__snapshots__/environment.test.ts.snap | 4 ++-- packages/cli/uni-builder/tests/default.test.ts | 2 +- packages/cli/uni-builder/tests/environment.test.ts | 4 ++-- packages/runtime/plugin-runtime/src/cli/ssr/index.ts | 2 +- .../tests/builder/__snapshots__/index.test.ts.snap | 8 ++++---- 9 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .changeset/hot-jobs-occur.md diff --git a/.changeset/hot-jobs-occur.md b/.changeset/hot-jobs-occur.md new file mode 100644 index 000000000000..fc2dc744fa73 --- /dev/null +++ b/.changeset/hot-jobs-occur.md @@ -0,0 +1,6 @@ +--- +'@modern-js/app-tools': patch +'@modern-js/uni-builder': patch +--- + +chore: rename serviceWorker environment name to workerSSR diff --git a/packages/cli/uni-builder/src/shared/plugins/environmentDefaults.ts b/packages/cli/uni-builder/src/shared/plugins/environmentDefaults.ts index 8b58cb14aa52..af11b6a471ad 100644 --- a/packages/cli/uni-builder/src/shared/plugins/environmentDefaults.ts +++ b/packages/cli/uni-builder/src/shared/plugins/environmentDefaults.ts @@ -58,7 +58,7 @@ export const pluginEnvironmentDefaults = ( // https://github.com/web-infra-dev/rsbuild/issues/2956 api.modifyRsbuildConfig({ handler: config => { - const environmentNameOrder = ['web', 'node', 'serviceWorker']; + const environmentNameOrder = ['web', 'node', 'workerSSR']; config.environments = Object.fromEntries( Object.entries(config.environments!).sort((a1, a2) => diff --git a/packages/cli/uni-builder/src/shared/utils.ts b/packages/cli/uni-builder/src/shared/utils.ts index 929b2b907fc7..6bb799bf0a62 100644 --- a/packages/cli/uni-builder/src/shared/utils.ts +++ b/packages/cli/uni-builder/src/shared/utils.ts @@ -8,7 +8,7 @@ import browserslist from 'browserslist'; export const RUNTIME_CHUNK_NAME = 'builder-runtime'; -export const SERVICE_WORKER_ENVIRONMENT_NAME = 'serviceWorker'; +export const SERVICE_WORKER_ENVIRONMENT_NAME = 'workerSSR'; export const JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/; diff --git a/packages/cli/uni-builder/tests/__snapshots__/default.test.ts.snap b/packages/cli/uni-builder/tests/__snapshots__/default.test.ts.snap index 0905155dda7d..bc91bbd66063 100644 --- a/packages/cli/uni-builder/tests/__snapshots__/default.test.ts.snap +++ b/packages/cli/uni-builder/tests/__snapshots__/default.test.ts.snap @@ -3303,7 +3303,7 @@ exports[`uni-builder rspack > should generator rspack config correctly when serv }, ], }, - "name": "serviceWorker", + "name": "workerSSR", "optimization": { "minimize": true, "minimizer": [ @@ -3374,7 +3374,7 @@ exports[`uni-builder rspack > should generator rspack config correctly when serv ProgressPlugin { "_args": [ { - "prefix": "serviceWorker", + "prefix": "workerSSR", }, ], "affectedHooks": undefined, diff --git a/packages/cli/uni-builder/tests/__snapshots__/environment.test.ts.snap b/packages/cli/uni-builder/tests/__snapshots__/environment.test.ts.snap index 4552b51add82..80d8d6380d62 100644 --- a/packages/cli/uni-builder/tests/__snapshots__/environment.test.ts.snap +++ b/packages/cli/uni-builder/tests/__snapshots__/environment.test.ts.snap @@ -2233,7 +2233,7 @@ exports[`uni-builder environment compat > should generator environment config co }, ], }, - "name": "serviceWorker", + "name": "workerSSR", "optimization": { "minimize": false, "splitChunks": false, @@ -2269,7 +2269,7 @@ exports[`uni-builder environment compat > should generator environment config co ProgressPlugin { "_args": [ { - "prefix": "serviceWorker", + "prefix": "workerSSR", }, ], "affectedHooks": undefined, diff --git a/packages/cli/uni-builder/tests/default.test.ts b/packages/cli/uni-builder/tests/default.test.ts index c2406129fac9..2f97c30ddd4f 100644 --- a/packages/cli/uni-builder/tests/default.test.ts +++ b/packages/cli/uni-builder/tests/default.test.ts @@ -77,7 +77,7 @@ describe('uni-builder rspack', () => { bundlerType: 'rspack', config: { environments: { - serviceWorker: { + workerSSR: { output: { target: 'web-worker', }, diff --git a/packages/cli/uni-builder/tests/environment.test.ts b/packages/cli/uni-builder/tests/environment.test.ts index 89d9b230fa1d..833f020a3ec2 100644 --- a/packages/cli/uni-builder/tests/environment.test.ts +++ b/packages/cli/uni-builder/tests/environment.test.ts @@ -16,7 +16,7 @@ describe('uni-builder environment compat', () => { target: 'node', }, }, - serviceWorker: { + workerSSR: { output: { target: 'web-worker', }, @@ -33,7 +33,7 @@ describe('uni-builder environment compat', () => { expect(bundlerConfigs.map(c => c.name)).toEqual([ 'web', 'node', - 'serviceWorker', + 'workerSSR', ]); expect(bundlerConfigs).toMatchSnapshot(); diff --git a/packages/runtime/plugin-runtime/src/cli/ssr/index.ts b/packages/runtime/plugin-runtime/src/cli/ssr/index.ts index a055f03e3ad6..8cf405cf2ec1 100644 --- a/packages/runtime/plugin-runtime/src/cli/ssr/index.ts +++ b/packages/runtime/plugin-runtime/src/cli/ssr/index.ts @@ -48,7 +48,7 @@ const ssrBuilderPlugin = (modernAPI: PluginAPI): RsbuildPlugin => ({ setup(api) { api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig }) => { const isServerEnvironment = - config.output.target === 'node' || name === 'serviceWorker'; + config.output.target === 'node' || name === 'workerSSR'; const userConfig = modernAPI.useResolvedConfigContext(); const useLoadablePlugin = diff --git a/packages/solutions/app-tools/tests/builder/__snapshots__/index.test.ts.snap b/packages/solutions/app-tools/tests/builder/__snapshots__/index.test.ts.snap index bbcabfab0572..bc84cafd89f8 100644 --- a/packages/solutions/app-tools/tests/builder/__snapshots__/index.test.ts.snap +++ b/packages/solutions/app-tools/tests/builder/__snapshots__/index.test.ts.snap @@ -60,9 +60,9 @@ exports[`create builder Options test create builder environments config 2`] = ` exports[`create builder Options test create builder environments config 3`] = ` { - "serviceWorker": { + "web": { "output": { - "target": "web-worker", + "target": "web", }, "source": { "entry": { @@ -76,9 +76,9 @@ exports[`create builder Options test create builder environments config 3`] = ` }, }, }, - "web": { + "workerSSR": { "output": { - "target": "web", + "target": "web-worker", }, "source": { "entry": {