From 339e77f2914fe2a498ad7778193c5afbfe2502c0 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Mon, 11 Nov 2024 17:35:57 +0800 Subject: [PATCH 1/3] feat!: target default to `node` --- examples/express-plugin/rslib.config.ts | 3 - .../mf-react-component/rslib.config.ts | 3 + .../rslib.config.ts | 3 + .../react-component-bundle/rslib.config.ts | 3 + examples/react-component-umd/rslib.config.ts | 3 + packages/core/rslib.config.ts | 1 + packages/core/src/config.ts | 6 +- packages/core/src/utils/syntax.ts | 6 +- .../tests/__snapshots__/config.test.ts.snap | 199 ++++++++++++++++-- packages/core/tests/config.test.ts | 6 - .../base/node-dual-js/rslib.config.mjs | 1 - .../base/node-dual-ts/rslib.config.ts | 1 - .../base/node-esm-js/rslib.config.mjs | 1 - .../base/node-esm-ts/rslib.config.ts | 1 - .../fragments/base/react-js/rslib.config.mjs | 3 + .../fragments/base/react-ts/rslib.config.ts | 3 + packages/create-rslib/rslib.config.ts | 1 + .../rslib.config.mjs | 1 - .../rslib.config.ts | 1 - .../rslib.config.mjs | 1 - .../rslib.config.ts | 1 - .../rslib.config.mjs | 1 - .../template-[node-esm]-[]-ts/rslib.config.ts | 1 - .../rslib.config.mjs | 1 - .../rslib.config.ts | 1 - .../template-[react]-[]-js/rslib.config.mjs | 3 + .../template-[react]-[]-ts/rslib.config.ts | 3 + .../rslib.config.mjs | 3 + .../rslib.config.ts | 3 + .../rslib.config.mjs | 3 + .../rslib.config.ts | 3 + .../rslib.config.mjs | 3 + .../rslib.config.ts | 3 + packages/plugin-dts/rslib.config.ts | 1 + tests/e2e/react-component/rsbuild.config.ts | 3 + tests/integration/asset/limit/rslib.config.ts | 3 + tests/integration/asset/name/rslib.config.ts | 3 + tests/integration/asset/path/rslib.config.ts | 3 + .../asset/public-path/rslib.config.ts | 3 + tests/integration/asset/svgr/rslib.config.ts | 3 + .../bundle-false/svgr/rslib.config.ts | 3 + .../externals/browser/rslib.config.ts | 1 + .../externals/node/rslib.config.ts | 3 +- .../integration/minify/config/rslib.config.ts | 1 - .../minify/default/rslib.config.ts | 3 - .../minify/mf/config/rslib.config.ts | 1 + .../minify/mf/default/rslib.config.ts | 3 + .../bundle-false/rslib.config.ts | 3 + .../node-polyfill/bundle/rslib.config.ts | 3 + .../require/import-dynamic/rslib.config.ts | 3 - .../require-as-expression/rslib.config.ts | 3 - .../require/require-dynamic/rslib.config.ts | 3 - .../require/require-resolve/rslib.config.ts | 3 - .../resolve/node-protocol/rslib.config.ts | 3 - .../with-condition-exports/rslib.config.ts | 2 +- .../resolve/with-main-fields/rslib.config.ts | 1 - tests/integration/shims/cjs/rslib.config.ts | 1 - tests/integration/shims/esm/rslib.config.ts | 3 - .../bundle-false-auto/rslib.config.ts | 1 + .../css-modules/bundle-false/rslib.config.ts | 3 + .../style/css-modules/bundle/rslib.config.ts | 3 + .../style/css/bundle-false/rslib.config.ts | 3 + .../style/css/bundle/rslib.config.ts | 3 + .../style/less/bundle-false/rslib.config.ts | 1 + .../style/less/bundle-import/rslib.config.ts | 3 + .../style/less/bundle/rslib.config.ts | 3 + .../lightningcss/bundle-false/rslib.config.ts | 3 + .../style/lightningcss/bundle/rslib.config.ts | 3 + .../postcss/bundle-false/rslib.config.ts | 3 + .../style/postcss/bundle/rslib.config.ts | 3 + .../redirect-style-false/rslib.config.ts | 1 + .../style/sass/bundle-false/rslib.config.ts | 11 +- .../style/sass/bundle/rslib.config.ts | 11 +- .../style/style-inject/bundle/rslib.config.ts | 1 + .../style/tailwindcss/bundle/rslib.config.ts | 3 + .../umd-library-name/rslib.config.ts | 3 + .../en/guide/advanced/module-federation.mdx | 3 + .../guide/advanced/output-compatibility.mdx | 2 +- website/docs/en/guide/basic/output-format.mdx | 3 + .../en/guide/migration/modernjs-module.mdx | 3 + website/docs/en/guide/migration/tsup.mdx | 8 +- website/docs/en/guide/solution/nodejs.mdx | 9 +- website/docs/en/guide/solution/react.mdx | 17 +- 83 files changed, 346 insertions(+), 99 deletions(-) diff --git a/examples/express-plugin/rslib.config.ts b/examples/express-plugin/rslib.config.ts index 3452d9301..5ef8af604 100644 --- a/examples/express-plugin/rslib.config.ts +++ b/examples/express-plugin/rslib.config.ts @@ -27,7 +27,4 @@ export default defineConfig({ }, }, ], - output: { - target: 'node', - }, }); diff --git a/examples/module-federation/mf-react-component/rslib.config.ts b/examples/module-federation/mf-react-component/rslib.config.ts index 8eb13c332..ced53fbfe 100644 --- a/examples/module-federation/mf-react-component/rslib.config.ts +++ b/examples/module-federation/mf-react-component/rslib.config.ts @@ -55,5 +55,8 @@ export default defineConfig({ ], }, ], + output: { + target: 'web', + }, plugins: [pluginReact()], }); diff --git a/examples/react-component-bundle-false/rslib.config.ts b/examples/react-component-bundle-false/rslib.config.ts index 7dd310a6f..a5a3fccd3 100644 --- a/examples/react-component-bundle-false/rslib.config.ts +++ b/examples/react-component-bundle-false/rslib.config.ts @@ -35,6 +35,9 @@ export default defineConfig({ }, }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/examples/react-component-bundle/rslib.config.ts b/examples/react-component-bundle/rslib.config.ts index 941177741..237965aed 100644 --- a/examples/react-component-bundle/rslib.config.ts +++ b/examples/react-component-bundle/rslib.config.ts @@ -33,6 +33,9 @@ export default defineConfig({ }, }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/examples/react-component-umd/rslib.config.ts b/examples/react-component-umd/rslib.config.ts index 97c1f0ebd..b5e4971bf 100644 --- a/examples/react-component-umd/rslib.config.ts +++ b/examples/react-component-umd/rslib.config.ts @@ -17,6 +17,9 @@ export default defineConfig({ }, }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/core/rslib.config.ts b/packages/core/rslib.config.ts index 4f725b59e..b894ac69b 100644 --- a/packages/core/rslib.config.ts +++ b/packages/core/rslib.config.ts @@ -21,6 +21,7 @@ export default defineConfig({ }, }, output: { + // TODO: Remove this after bumping Rslib target: 'node', externals: { picocolors: '../compiled/picocolors/index.js', diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index a0d57763f..c5eb1d6ef 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -453,6 +453,7 @@ export async function createConstantRsbuildConfig(): Promise { }, }, output: { + target: 'node', filenameHash: false, distPath: { js: './', @@ -558,7 +559,6 @@ const composeFormatConfig = ({ }, output: { asyncChunks: false, - library: umdName ? { type: 'umd', @@ -714,7 +714,7 @@ const composeAutoExtensionConfig = ( const composeSyntaxConfig = ( syntax?: Syntax, - target?: RsbuildConfigOutputTarget, + target: RsbuildConfigOutputTarget = 'node', ): RsbuildConfig => { // Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported. if (syntax) { @@ -941,7 +941,7 @@ const composeDtsConfig = async ( }; const composeTargetConfig = ( - target: RsbuildConfigOutputTarget = 'web', + target: RsbuildConfigOutputTarget = 'node', ): RsbuildConfig => { switch (target) { case 'web': diff --git a/packages/core/src/utils/syntax.ts b/packages/core/src/utils/syntax.ts index a62c93612..7ab9aa0c9 100644 --- a/packages/core/src/utils/syntax.ts +++ b/packages/core/src/utils/syntax.ts @@ -26,10 +26,6 @@ export const LATEST_TARGET_VERSIONS: Record< }; const calcEsnextBrowserslistByTarget = (target: RsbuildConfigOutputTarget) => { - if (!target) { - return [...LATEST_TARGET_VERSIONS.node, ...LATEST_TARGET_VERSIONS.web]; - } - if (target === 'node') { return LATEST_TARGET_VERSIONS.node; } @@ -195,7 +191,7 @@ export function transformSyntaxToRspackTarget( export function transformSyntaxToBrowserslist( syntax: Syntax, - target?: NonNullable['target'], + target: NonNullable['target'], ): NonNullable['overrideBrowserslist']> { const handleSyntaxItem = ( syntaxItem: EcmaScriptVersion | string, diff --git a/packages/core/tests/__snapshots__/config.test.ts.snap b/packages/core/tests/__snapshots__/config.test.ts.snap index e24313b11..085442d24 100644 --- a/packages/core/tests/__snapshots__/config.test.ts.snap +++ b/packages/core/tests/__snapshots__/config.test.ts.snap @@ -14,6 +14,62 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, "externals": [ [Function], + "assert", + "assert/strict", + "async_hooks", + "buffer", + "child_process", + "cluster", + "console", + "constants", + "crypto", + "dgram", + "diagnostics_channel", + "dns", + "dns/promises", + "domain", + "events", + "fs", + "fs/promises", + "http", + "http2", + "https", + "inspector", + "inspector/promises", + "module", + "net", + "os", + "path", + "path/posix", + "path/win32", + "perf_hooks", + "process", + "punycode", + "querystring", + "readline", + "readline/promises", + "repl", + "stream", + "stream/consumers", + "stream/promises", + "stream/web", + "string_decoder", + "sys", + "timers", + "timers/promises", + "tls", + "trace_events", + "tty", + "url", + "util", + "util/types", + "v8", + "vm", + "wasi", + "worker_threads", + "zlib", + /\\^node:/, + "pnpapi", ], "filename": { "js": "[name].js", @@ -40,13 +96,8 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, "overrideBrowserslist": [ "last 1 node versions", - "last 1 Chrome versions", - "last 1 Firefox versions", - "last 1 Edge versions", - "last 1 Safari versions", - "last 1 ios_saf versions", - "not dead", ], + "target": "node", }, "performance": { "chunkSplit": { @@ -141,7 +192,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 [Function], { "target": [ - "web", + "node", ], }, { @@ -174,6 +225,64 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "distPath": { "js": "./", }, + "externals": [ + "assert", + "assert/strict", + "async_hooks", + "buffer", + "child_process", + "cluster", + "console", + "constants", + "crypto", + "dgram", + "diagnostics_channel", + "dns", + "dns/promises", + "domain", + "events", + "fs", + "fs/promises", + "http", + "http2", + "https", + "inspector", + "inspector/promises", + "module", + "net", + "os", + "path", + "path/posix", + "path/win32", + "perf_hooks", + "process", + "punycode", + "querystring", + "readline", + "readline/promises", + "repl", + "stream", + "stream/consumers", + "stream/promises", + "stream/web", + "string_decoder", + "sys", + "timers", + "timers/promises", + "tls", + "trace_events", + "tty", + "url", + "util", + "util/types", + "v8", + "vm", + "wasi", + "worker_threads", + "zlib", + /\\^node:/, + "pnpapi", + ], "filename": { "js": "[name].js", }, @@ -199,13 +308,8 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, "overrideBrowserslist": [ "last 1 node versions", - "last 1 Chrome versions", - "last 1 Firefox versions", - "last 1 Edge versions", - "last 1 Safari versions", - "last 1 ios_saf versions", - "not dead", ], + "target": "node", }, "performance": { "chunkSplit": { @@ -298,7 +402,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 [Function], { "target": [ - "web", + "node", ], }, { @@ -331,6 +435,64 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "distPath": { "js": "./", }, + "externals": [ + "assert", + "assert/strict", + "async_hooks", + "buffer", + "child_process", + "cluster", + "console", + "constants", + "crypto", + "dgram", + "diagnostics_channel", + "dns", + "dns/promises", + "domain", + "events", + "fs", + "fs/promises", + "http", + "http2", + "https", + "inspector", + "inspector/promises", + "module", + "net", + "os", + "path", + "path/posix", + "path/win32", + "perf_hooks", + "process", + "punycode", + "querystring", + "readline", + "readline/promises", + "repl", + "stream", + "stream/consumers", + "stream/promises", + "stream/web", + "string_decoder", + "sys", + "timers", + "timers/promises", + "tls", + "trace_events", + "tty", + "url", + "util", + "util/types", + "v8", + "vm", + "wasi", + "worker_threads", + "zlib", + /\\^node:/, + "pnpapi", + ], "filename": { "js": "[name].js", }, @@ -356,13 +518,8 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, "overrideBrowserslist": [ "last 1 node versions", - "last 1 Chrome versions", - "last 1 Firefox versions", - "last 1 Edge versions", - "last 1 Safari versions", - "last 1 ios_saf versions", - "not dead", ], + "target": "node", }, "performance": { "chunkSplit": { @@ -437,7 +594,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 [Function], { "target": [ - "web", + "node", ], }, { diff --git a/packages/core/tests/config.test.ts b/packages/core/tests/config.test.ts index 7ad92da72..d766030e9 100644 --- a/packages/core/tests/config.test.ts +++ b/packages/core/tests/config.test.ts @@ -217,12 +217,6 @@ describe('syntax', () => { ).toMatchInlineSnapshot(` [ "last 1 node versions", - "last 1 Chrome versions", - "last 1 Firefox versions", - "last 1 Edge versions", - "last 1 Safari versions", - "last 1 ios_saf versions", - "not dead", ] `); }); diff --git a/packages/create-rslib/fragments/base/node-dual-js/rslib.config.mjs b/packages/create-rslib/fragments/base/node-dual-js/rslib.config.mjs index 2e440385b..31c250f4d 100644 --- a/packages/create-rslib/fragments/base/node-dual-js/rslib.config.mjs +++ b/packages/create-rslib/fragments/base/node-dual-js/rslib.config.mjs @@ -11,5 +11,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/fragments/base/node-dual-ts/rslib.config.ts b/packages/create-rslib/fragments/base/node-dual-ts/rslib.config.ts index cfac2795e..e9397a12f 100644 --- a/packages/create-rslib/fragments/base/node-dual-ts/rslib.config.ts +++ b/packages/create-rslib/fragments/base/node-dual-ts/rslib.config.ts @@ -12,5 +12,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/fragments/base/node-esm-js/rslib.config.mjs b/packages/create-rslib/fragments/base/node-esm-js/rslib.config.mjs index 5b320ba49..1f7f7569e 100644 --- a/packages/create-rslib/fragments/base/node-esm-js/rslib.config.mjs +++ b/packages/create-rslib/fragments/base/node-esm-js/rslib.config.mjs @@ -7,5 +7,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/fragments/base/node-esm-ts/rslib.config.ts b/packages/create-rslib/fragments/base/node-esm-ts/rslib.config.ts index 88195290c..9b69a2951 100644 --- a/packages/create-rslib/fragments/base/node-esm-ts/rslib.config.ts +++ b/packages/create-rslib/fragments/base/node-esm-ts/rslib.config.ts @@ -8,5 +8,4 @@ export default defineConfig({ dts: true, }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/fragments/base/react-js/rslib.config.mjs b/packages/create-rslib/fragments/base/react-js/rslib.config.mjs index 7717aff12..ea02edfa7 100644 --- a/packages/create-rslib/fragments/base/react-js/rslib.config.mjs +++ b/packages/create-rslib/fragments/base/react-js/rslib.config.mjs @@ -13,6 +13,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/fragments/base/react-ts/rslib.config.ts b/packages/create-rslib/fragments/base/react-ts/rslib.config.ts index 5ae8d4675..03bb9f7a5 100644 --- a/packages/create-rslib/fragments/base/react-ts/rslib.config.ts +++ b/packages/create-rslib/fragments/base/react-ts/rslib.config.ts @@ -14,6 +14,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/rslib.config.ts b/packages/create-rslib/rslib.config.ts index 65d00bf22..b74aaa0ed 100644 --- a/packages/create-rslib/rslib.config.ts +++ b/packages/create-rslib/rslib.config.ts @@ -2,6 +2,7 @@ import { defineConfig } from 'rslib'; export default defineConfig({ lib: [{ format: 'esm' }], + // TODO: Remove this after bumping Rslib output: { target: 'node', }, diff --git a/packages/create-rslib/template-[node-dual]-[]-js/rslib.config.mjs b/packages/create-rslib/template-[node-dual]-[]-js/rslib.config.mjs index 2e440385b..31c250f4d 100644 --- a/packages/create-rslib/template-[node-dual]-[]-js/rslib.config.mjs +++ b/packages/create-rslib/template-[node-dual]-[]-js/rslib.config.mjs @@ -11,5 +11,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/template-[node-dual]-[]-ts/rslib.config.ts b/packages/create-rslib/template-[node-dual]-[]-ts/rslib.config.ts index cfac2795e..e9397a12f 100644 --- a/packages/create-rslib/template-[node-dual]-[]-ts/rslib.config.ts +++ b/packages/create-rslib/template-[node-dual]-[]-ts/rslib.config.ts @@ -12,5 +12,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/template-[node-dual]-[vitest]-js/rslib.config.mjs b/packages/create-rslib/template-[node-dual]-[vitest]-js/rslib.config.mjs index 2e440385b..31c250f4d 100644 --- a/packages/create-rslib/template-[node-dual]-[vitest]-js/rslib.config.mjs +++ b/packages/create-rslib/template-[node-dual]-[vitest]-js/rslib.config.mjs @@ -11,5 +11,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/template-[node-dual]-[vitest]-ts/rslib.config.ts b/packages/create-rslib/template-[node-dual]-[vitest]-ts/rslib.config.ts index cfac2795e..e9397a12f 100644 --- a/packages/create-rslib/template-[node-dual]-[vitest]-ts/rslib.config.ts +++ b/packages/create-rslib/template-[node-dual]-[vitest]-ts/rslib.config.ts @@ -12,5 +12,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/template-[node-esm]-[]-js/rslib.config.mjs b/packages/create-rslib/template-[node-esm]-[]-js/rslib.config.mjs index 5b320ba49..1f7f7569e 100644 --- a/packages/create-rslib/template-[node-esm]-[]-js/rslib.config.mjs +++ b/packages/create-rslib/template-[node-esm]-[]-js/rslib.config.mjs @@ -7,5 +7,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/template-[node-esm]-[]-ts/rslib.config.ts b/packages/create-rslib/template-[node-esm]-[]-ts/rslib.config.ts index 88195290c..9b69a2951 100644 --- a/packages/create-rslib/template-[node-esm]-[]-ts/rslib.config.ts +++ b/packages/create-rslib/template-[node-esm]-[]-ts/rslib.config.ts @@ -8,5 +8,4 @@ export default defineConfig({ dts: true, }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/template-[node-esm]-[vitest]-js/rslib.config.mjs b/packages/create-rslib/template-[node-esm]-[vitest]-js/rslib.config.mjs index 5b320ba49..1f7f7569e 100644 --- a/packages/create-rslib/template-[node-esm]-[vitest]-js/rslib.config.mjs +++ b/packages/create-rslib/template-[node-esm]-[vitest]-js/rslib.config.mjs @@ -7,5 +7,4 @@ export default defineConfig({ syntax: 'es2021', }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/template-[node-esm]-[vitest]-ts/rslib.config.ts b/packages/create-rslib/template-[node-esm]-[vitest]-ts/rslib.config.ts index 88195290c..9b69a2951 100644 --- a/packages/create-rslib/template-[node-esm]-[vitest]-ts/rslib.config.ts +++ b/packages/create-rslib/template-[node-esm]-[vitest]-ts/rslib.config.ts @@ -8,5 +8,4 @@ export default defineConfig({ dts: true, }, ], - output: { target: 'node' }, }); diff --git a/packages/create-rslib/template-[react]-[]-js/rslib.config.mjs b/packages/create-rslib/template-[react]-[]-js/rslib.config.mjs index 7717aff12..ea02edfa7 100644 --- a/packages/create-rslib/template-[react]-[]-js/rslib.config.mjs +++ b/packages/create-rslib/template-[react]-[]-js/rslib.config.mjs @@ -13,6 +13,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/template-[react]-[]-ts/rslib.config.ts b/packages/create-rslib/template-[react]-[]-ts/rslib.config.ts index 5ae8d4675..03bb9f7a5 100644 --- a/packages/create-rslib/template-[react]-[]-ts/rslib.config.ts +++ b/packages/create-rslib/template-[react]-[]-ts/rslib.config.ts @@ -14,6 +14,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/template-[react]-[storybook,vitest]-js/rslib.config.mjs b/packages/create-rslib/template-[react]-[storybook,vitest]-js/rslib.config.mjs index 7717aff12..ea02edfa7 100644 --- a/packages/create-rslib/template-[react]-[storybook,vitest]-js/rslib.config.mjs +++ b/packages/create-rslib/template-[react]-[storybook,vitest]-js/rslib.config.mjs @@ -13,6 +13,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/template-[react]-[storybook,vitest]-ts/rslib.config.ts b/packages/create-rslib/template-[react]-[storybook,vitest]-ts/rslib.config.ts index 5ae8d4675..03bb9f7a5 100644 --- a/packages/create-rslib/template-[react]-[storybook,vitest]-ts/rslib.config.ts +++ b/packages/create-rslib/template-[react]-[storybook,vitest]-ts/rslib.config.ts @@ -14,6 +14,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/template-[react]-[storybook]-js/rslib.config.mjs b/packages/create-rslib/template-[react]-[storybook]-js/rslib.config.mjs index 7717aff12..ea02edfa7 100644 --- a/packages/create-rslib/template-[react]-[storybook]-js/rslib.config.mjs +++ b/packages/create-rslib/template-[react]-[storybook]-js/rslib.config.mjs @@ -13,6 +13,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/template-[react]-[storybook]-ts/rslib.config.ts b/packages/create-rslib/template-[react]-[storybook]-ts/rslib.config.ts index 5ae8d4675..03bb9f7a5 100644 --- a/packages/create-rslib/template-[react]-[storybook]-ts/rslib.config.ts +++ b/packages/create-rslib/template-[react]-[storybook]-ts/rslib.config.ts @@ -14,6 +14,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/template-[react]-[vitest]-js/rslib.config.mjs b/packages/create-rslib/template-[react]-[vitest]-js/rslib.config.mjs index 7717aff12..ea02edfa7 100644 --- a/packages/create-rslib/template-[react]-[vitest]-js/rslib.config.mjs +++ b/packages/create-rslib/template-[react]-[vitest]-js/rslib.config.mjs @@ -13,6 +13,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/create-rslib/template-[react]-[vitest]-ts/rslib.config.ts b/packages/create-rslib/template-[react]-[vitest]-ts/rslib.config.ts index 5ae8d4675..03bb9f7a5 100644 --- a/packages/create-rslib/template-[react]-[vitest]-ts/rslib.config.ts +++ b/packages/create-rslib/template-[react]-[vitest]-ts/rslib.config.ts @@ -14,6 +14,9 @@ export default defineConfig({ format: 'esm', }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/packages/plugin-dts/rslib.config.ts b/packages/plugin-dts/rslib.config.ts index 8e03e15f5..beacf3928 100644 --- a/packages/plugin-dts/rslib.config.ts +++ b/packages/plugin-dts/rslib.config.ts @@ -16,6 +16,7 @@ export default defineConfig({ index: ['./src/**'], }, }, + // TODO: Remove this after bumping Rslib output: { target: 'node', }, diff --git a/tests/e2e/react-component/rsbuild.config.ts b/tests/e2e/react-component/rsbuild.config.ts index ff826363f..e282fa951 100644 --- a/tests/e2e/react-component/rsbuild.config.ts +++ b/tests/e2e/react-component/rsbuild.config.ts @@ -60,5 +60,8 @@ export default defineConfig({ }, }, }, + output: { + target: 'web', + }, plugins: [pluginReact()], }); diff --git a/tests/integration/asset/limit/rslib.config.ts b/tests/integration/asset/limit/rslib.config.ts index 9c9e5b896..b82c816c1 100644 --- a/tests/integration/asset/limit/rslib.config.ts +++ b/tests/integration/asset/limit/rslib.config.ts @@ -45,4 +45,7 @@ export default defineConfig({ index: './src/index.js', }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/asset/name/rslib.config.ts b/tests/integration/asset/name/rslib.config.ts index 41a62905e..0a70ba02e 100644 --- a/tests/integration/asset/name/rslib.config.ts +++ b/tests/integration/asset/name/rslib.config.ts @@ -31,5 +31,8 @@ export default defineConfig({ index: './src/index.jsx', }, }, + output: { + target: 'web', + }, plugins: [pluginReact()], }); diff --git a/tests/integration/asset/path/rslib.config.ts b/tests/integration/asset/path/rslib.config.ts index aca26ef5a..5881be935 100644 --- a/tests/integration/asset/path/rslib.config.ts +++ b/tests/integration/asset/path/rslib.config.ts @@ -26,4 +26,7 @@ export default defineConfig({ index: './src/index.js', }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/asset/public-path/rslib.config.ts b/tests/integration/asset/public-path/rslib.config.ts index 7314ce292..cb025d05a 100644 --- a/tests/integration/asset/public-path/rslib.config.ts +++ b/tests/integration/asset/public-path/rslib.config.ts @@ -32,4 +32,7 @@ export default defineConfig({ index: './src/index.js', }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/asset/svgr/rslib.config.ts b/tests/integration/asset/svgr/rslib.config.ts index 675713e04..6318ab07a 100644 --- a/tests/integration/asset/svgr/rslib.config.ts +++ b/tests/integration/asset/svgr/rslib.config.ts @@ -72,5 +72,8 @@ export default defineConfig({ ], }), ], + output: { + target: 'web', + }, plugins: [pluginReact()], }); diff --git a/tests/integration/bundle-false/svgr/rslib.config.ts b/tests/integration/bundle-false/svgr/rslib.config.ts index 20dbe11a8..17aa8a6e4 100644 --- a/tests/integration/bundle-false/svgr/rslib.config.ts +++ b/tests/integration/bundle-false/svgr/rslib.config.ts @@ -17,5 +17,8 @@ export default defineConfig({ index: ['./src/**'], }, }, + output: { + target: 'web', + }, plugins: [pluginReact(), pluginSvgr()], }); diff --git a/tests/integration/externals/browser/rslib.config.ts b/tests/integration/externals/browser/rslib.config.ts index 843e34d16..94a477e58 100644 --- a/tests/integration/externals/browser/rslib.config.ts +++ b/tests/integration/externals/browser/rslib.config.ts @@ -10,5 +10,6 @@ export default defineConfig({ }, output: { externals: { react: 'react' }, + target: 'web', }, }); diff --git a/tests/integration/externals/node/rslib.config.ts b/tests/integration/externals/node/rslib.config.ts index ffac0872e..4c6bd9192 100644 --- a/tests/integration/externals/node/rslib.config.ts +++ b/tests/integration/externals/node/rslib.config.ts @@ -5,12 +5,11 @@ export default defineConfig({ lib: [ generateBundleEsmConfig({ output: { - target: 'node', externals: { foo: 'node-commonjs foo' }, }, }), generateBundleCjsConfig({ - output: { target: 'node', externals: { foo: 'foo' } }, + output: { externals: { foo: 'foo' } }, }), ], source: { diff --git a/tests/integration/minify/config/rslib.config.ts b/tests/integration/minify/config/rslib.config.ts index 0722397f2..30d5a147c 100644 --- a/tests/integration/minify/config/rslib.config.ts +++ b/tests/integration/minify/config/rslib.config.ts @@ -5,7 +5,6 @@ import { generateBundleEsmConfig } from 'test-helper'; export default defineConfig({ lib: [generateBundleEsmConfig()], output: { - target: 'node', minify: false, }, source: { diff --git a/tests/integration/minify/default/rslib.config.ts b/tests/integration/minify/default/rslib.config.ts index 3cde45244..8ed99602c 100644 --- a/tests/integration/minify/default/rslib.config.ts +++ b/tests/integration/minify/default/rslib.config.ts @@ -4,9 +4,6 @@ import { generateBundleEsmConfig } from 'test-helper'; export default defineConfig({ lib: [generateBundleEsmConfig()], - output: { - target: 'node', - }, source: { entry: { index: path.resolve(__dirname, '../__fixtures__/src/index.ts'), diff --git a/tests/integration/minify/mf/config/rslib.config.ts b/tests/integration/minify/mf/config/rslib.config.ts index 9e236e661..6e0754071 100644 --- a/tests/integration/minify/mf/config/rslib.config.ts +++ b/tests/integration/minify/mf/config/rslib.config.ts @@ -28,6 +28,7 @@ export default defineConfig({ }, }, output: { + target: 'web', minify: false, }, source: { diff --git a/tests/integration/minify/mf/default/rslib.config.ts b/tests/integration/minify/mf/default/rslib.config.ts index bf7d466d7..d01b23feb 100644 --- a/tests/integration/minify/mf/default/rslib.config.ts +++ b/tests/integration/minify/mf/default/rslib.config.ts @@ -32,4 +32,7 @@ export default defineConfig({ index: path.resolve(__dirname, '../../__fixtures__/src/index.ts'), }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/node-polyfill/bundle-false/rslib.config.ts b/tests/integration/node-polyfill/bundle-false/rslib.config.ts index b7dd56d26..4eb000952 100644 --- a/tests/integration/node-polyfill/bundle-false/rslib.config.ts +++ b/tests/integration/node-polyfill/bundle-false/rslib.config.ts @@ -28,6 +28,9 @@ export default defineConfig({ }, }), ], + output: { + target: 'web', + }, plugins: [pluginNodePolyfill()], source: { entry: { diff --git a/tests/integration/node-polyfill/bundle/rslib.config.ts b/tests/integration/node-polyfill/bundle/rslib.config.ts index 6edd96393..0657fa596 100644 --- a/tests/integration/node-polyfill/bundle/rslib.config.ts +++ b/tests/integration/node-polyfill/bundle/rslib.config.ts @@ -21,6 +21,9 @@ export default defineConfig({ }, }), ], + output: { + target: 'web', + }, plugins: [pluginNodePolyfill()], source: { entry: { diff --git a/tests/integration/require/import-dynamic/rslib.config.ts b/tests/integration/require/import-dynamic/rslib.config.ts index 67fafd2b8..388ed9b6c 100644 --- a/tests/integration/require/import-dynamic/rslib.config.ts +++ b/tests/integration/require/import-dynamic/rslib.config.ts @@ -3,9 +3,6 @@ import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper'; export default defineConfig({ lib: [generateBundleEsmConfig(), generateBundleCjsConfig()], - output: { - target: 'node', - }, source: { entry: { index: './index.ts', diff --git a/tests/integration/require/require-as-expression/rslib.config.ts b/tests/integration/require/require-as-expression/rslib.config.ts index e0264b270..bde34c8e1 100644 --- a/tests/integration/require/require-as-expression/rslib.config.ts +++ b/tests/integration/require/require-as-expression/rslib.config.ts @@ -3,9 +3,6 @@ import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper'; export default defineConfig({ lib: [generateBundleEsmConfig(), generateBundleCjsConfig()], - output: { - target: 'node', - }, source: { entry: { index: './index.js', diff --git a/tests/integration/require/require-dynamic/rslib.config.ts b/tests/integration/require/require-dynamic/rslib.config.ts index 67fafd2b8..388ed9b6c 100644 --- a/tests/integration/require/require-dynamic/rslib.config.ts +++ b/tests/integration/require/require-dynamic/rslib.config.ts @@ -3,9 +3,6 @@ import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper'; export default defineConfig({ lib: [generateBundleEsmConfig(), generateBundleCjsConfig()], - output: { - target: 'node', - }, source: { entry: { index: './index.ts', diff --git a/tests/integration/require/require-resolve/rslib.config.ts b/tests/integration/require/require-resolve/rslib.config.ts index 67fafd2b8..388ed9b6c 100644 --- a/tests/integration/require/require-resolve/rslib.config.ts +++ b/tests/integration/require/require-resolve/rslib.config.ts @@ -3,9 +3,6 @@ import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper'; export default defineConfig({ lib: [generateBundleEsmConfig(), generateBundleCjsConfig()], - output: { - target: 'node', - }, source: { entry: { index: './index.ts', diff --git a/tests/integration/resolve/node-protocol/rslib.config.ts b/tests/integration/resolve/node-protocol/rslib.config.ts index b7b8089f7..388ed9b6c 100644 --- a/tests/integration/resolve/node-protocol/rslib.config.ts +++ b/tests/integration/resolve/node-protocol/rslib.config.ts @@ -8,7 +8,4 @@ export default defineConfig({ index: './index.ts', }, }, - output: { - target: 'node', - }, }); diff --git a/tests/integration/resolve/with-condition-exports/rslib.config.ts b/tests/integration/resolve/with-condition-exports/rslib.config.ts index 50c7862a1..868f39600 100644 --- a/tests/integration/resolve/with-condition-exports/rslib.config.ts +++ b/tests/integration/resolve/with-condition-exports/rslib.config.ts @@ -8,7 +8,6 @@ export default defineConfig({ distPath: { root: './dist/node', }, - target: 'node', }, }), generateBundleEsmConfig({ @@ -16,6 +15,7 @@ export default defineConfig({ distPath: { root: './dist/browser', }, + target: 'web', }, }), ], diff --git a/tests/integration/resolve/with-main-fields/rslib.config.ts b/tests/integration/resolve/with-main-fields/rslib.config.ts index 802ba2f1a..77bba8884 100644 --- a/tests/integration/resolve/with-main-fields/rslib.config.ts +++ b/tests/integration/resolve/with-main-fields/rslib.config.ts @@ -22,7 +22,6 @@ export default defineConfig({ distPath: { root: './dist/node', }, - target: 'node', }, source: { entry: { diff --git a/tests/integration/shims/cjs/rslib.config.ts b/tests/integration/shims/cjs/rslib.config.ts index 2b558cd15..9e95a40ac 100644 --- a/tests/integration/shims/cjs/rslib.config.ts +++ b/tests/integration/shims/cjs/rslib.config.ts @@ -11,7 +11,6 @@ export default defineConfig({ }), ], output: { - target: 'node', copy: [{ from: 'src/ok.cjs' }], }, source: { diff --git a/tests/integration/shims/esm/rslib.config.ts b/tests/integration/shims/esm/rslib.config.ts index 5628aa7f2..c2cdcbec2 100644 --- a/tests/integration/shims/esm/rslib.config.ts +++ b/tests/integration/shims/esm/rslib.config.ts @@ -46,7 +46,4 @@ export default defineConfig({ }, }), ], - output: { - target: 'node', - }, }); diff --git a/tests/integration/style/css-modules/bundle-false-auto/rslib.config.ts b/tests/integration/style/css-modules/bundle-false-auto/rslib.config.ts index bf921ff48..020b3f5c8 100644 --- a/tests/integration/style/css-modules/bundle-false-auto/rslib.config.ts +++ b/tests/integration/style/css-modules/bundle-false-auto/rslib.config.ts @@ -20,6 +20,7 @@ export default defineConfig({ }), ], output: { + target: 'web', cssModules: { auto: /\.scss/, }, diff --git a/tests/integration/style/css-modules/bundle-false/rslib.config.ts b/tests/integration/style/css-modules/bundle-false/rslib.config.ts index 2ea1e042b..df82701d0 100644 --- a/tests/integration/style/css-modules/bundle-false/rslib.config.ts +++ b/tests/integration/style/css-modules/bundle-false/rslib.config.ts @@ -12,6 +12,9 @@ export default defineConfig({ index: ['../__fixtures__/basic/src/**'], }, }, + output: { + target: 'web', + }, plugins: [ pluginSass({ sassLoaderOptions: { diff --git a/tests/integration/style/css-modules/bundle/rslib.config.ts b/tests/integration/style/css-modules/bundle/rslib.config.ts index a18391047..90930aa8f 100644 --- a/tests/integration/style/css-modules/bundle/rslib.config.ts +++ b/tests/integration/style/css-modules/bundle/rslib.config.ts @@ -9,6 +9,9 @@ export default defineConfig({ index: ['../__fixtures__/basic/src/index.ts'], }, }, + output: { + target: 'web', + }, plugins: [ pluginSass({ sassLoaderOptions: { diff --git a/tests/integration/style/css/bundle-false/rslib.config.ts b/tests/integration/style/css/bundle-false/rslib.config.ts index 73218ed2f..d144c0b13 100644 --- a/tests/integration/style/css/bundle-false/rslib.config.ts +++ b/tests/integration/style/css/bundle-false/rslib.config.ts @@ -11,4 +11,7 @@ export default defineConfig({ index: ['../__fixtures__/basic/src/**/*.css'], }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/style/css/bundle/rslib.config.ts b/tests/integration/style/css/bundle/rslib.config.ts index 5a9a0c3d3..dacd0d949 100644 --- a/tests/integration/style/css/bundle/rslib.config.ts +++ b/tests/integration/style/css/bundle/rslib.config.ts @@ -8,4 +8,7 @@ export default defineConfig({ index: '../__fixtures__/basic/src/import.css', }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/style/less/bundle-false/rslib.config.ts b/tests/integration/style/less/bundle-false/rslib.config.ts index ca9dcb75f..b4afac27e 100644 --- a/tests/integration/style/less/bundle-false/rslib.config.ts +++ b/tests/integration/style/less/bundle-false/rslib.config.ts @@ -29,6 +29,7 @@ export default defineConfig({ }), ], output: { + target: 'web', // TODO: support asset // dataUriLimit: 0 }, diff --git a/tests/integration/style/less/bundle-import/rslib.config.ts b/tests/integration/style/less/bundle-import/rslib.config.ts index ac559ed66..fb6cb7826 100644 --- a/tests/integration/style/less/bundle-import/rslib.config.ts +++ b/tests/integration/style/less/bundle-import/rslib.config.ts @@ -9,5 +9,8 @@ export default defineConfig({ index: ['../__fixtures__/import/src/index.ts'], }, }, + output: { + target: 'web', + }, plugins: [pluginLess()], }); diff --git a/tests/integration/style/less/bundle/rslib.config.ts b/tests/integration/style/less/bundle/rslib.config.ts index 18bcbe877..b45dca44d 100644 --- a/tests/integration/style/less/bundle/rslib.config.ts +++ b/tests/integration/style/less/bundle/rslib.config.ts @@ -15,6 +15,9 @@ export default defineConfig({ ), }, }, + output: { + target: 'web', + }, plugins: [ pluginLess({ lessLoaderOptions: { diff --git a/tests/integration/style/lightningcss/bundle-false/rslib.config.ts b/tests/integration/style/lightningcss/bundle-false/rslib.config.ts index 4c0b2192f..34bcb2783 100644 --- a/tests/integration/style/lightningcss/bundle-false/rslib.config.ts +++ b/tests/integration/style/lightningcss/bundle-false/rslib.config.ts @@ -11,4 +11,7 @@ export default defineConfig({ index: ['../__fixtures__/basic/src/*.css'], }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/style/lightningcss/bundle/rslib.config.ts b/tests/integration/style/lightningcss/bundle/rslib.config.ts index 1dad8ed1c..6de130e75 100644 --- a/tests/integration/style/lightningcss/bundle/rslib.config.ts +++ b/tests/integration/style/lightningcss/bundle/rslib.config.ts @@ -8,4 +8,7 @@ export default defineConfig({ index: ['../__fixtures__/basic/src/index.css'], }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/style/postcss/bundle-false/rslib.config.ts b/tests/integration/style/postcss/bundle-false/rslib.config.ts index 4e23ba808..9adc1a4a7 100644 --- a/tests/integration/style/postcss/bundle-false/rslib.config.ts +++ b/tests/integration/style/postcss/bundle-false/rslib.config.ts @@ -19,4 +19,7 @@ export default defineConfig({ }, }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/style/postcss/bundle/rslib.config.ts b/tests/integration/style/postcss/bundle/rslib.config.ts index bba694410..71d96af06 100644 --- a/tests/integration/style/postcss/bundle/rslib.config.ts +++ b/tests/integration/style/postcss/bundle/rslib.config.ts @@ -16,4 +16,7 @@ export default defineConfig({ }, }, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/style/redirect-style-false/rslib.config.ts b/tests/integration/style/redirect-style-false/rslib.config.ts index b2796fb33..e4aa58126 100644 --- a/tests/integration/style/redirect-style-false/rslib.config.ts +++ b/tests/integration/style/redirect-style-false/rslib.config.ts @@ -22,6 +22,7 @@ export default defineConfig({ }, }, output: { + target: 'web', copy: [{ from: './src/index.less' }, { from: './src/style.module.less' }], }, }); diff --git a/tests/integration/style/sass/bundle-false/rslib.config.ts b/tests/integration/style/sass/bundle-false/rslib.config.ts index b07f07bf9..79c602f7e 100644 --- a/tests/integration/style/sass/bundle-false/rslib.config.ts +++ b/tests/integration/style/sass/bundle-false/rslib.config.ts @@ -23,9 +23,10 @@ export default defineConfig({ }, }), ], - // output: { - // dataUriLimit: { - // svg: 0 - // } - // } + output: { + target: 'web', + // dataUriLimit: { + // svg: 0 + // } + }, }); diff --git a/tests/integration/style/sass/bundle/rslib.config.ts b/tests/integration/style/sass/bundle/rslib.config.ts index 4d18c4f25..dc80e308a 100644 --- a/tests/integration/style/sass/bundle/rslib.config.ts +++ b/tests/integration/style/sass/bundle/rslib.config.ts @@ -16,9 +16,10 @@ export default defineConfig({ }, }), ], - // output: { - // dataUriLimit: { - // svg: 0 - // } - // } + output: { + target: 'web', + // dataUriLimit: { + // svg: 0, + // }, + }, }); diff --git a/tests/integration/style/style-inject/bundle/rslib.config.ts b/tests/integration/style/style-inject/bundle/rslib.config.ts index b649cf8a8..b9a953531 100644 --- a/tests/integration/style/style-inject/bundle/rslib.config.ts +++ b/tests/integration/style/style-inject/bundle/rslib.config.ts @@ -9,6 +9,7 @@ export default defineConfig({ }, }, output: { + target: 'web', injectStyles: true, }, }); diff --git a/tests/integration/style/tailwindcss/bundle/rslib.config.ts b/tests/integration/style/tailwindcss/bundle/rslib.config.ts index a9b4c1f8c..96ab47b68 100644 --- a/tests/integration/style/tailwindcss/bundle/rslib.config.ts +++ b/tests/integration/style/tailwindcss/bundle/rslib.config.ts @@ -11,4 +11,7 @@ export default defineConfig({ tools: { lightningcssLoader: false, }, + output: { + target: 'web', + }, }); diff --git a/tests/integration/umd-library-name/rslib.config.ts b/tests/integration/umd-library-name/rslib.config.ts index 161c0e549..a293c4d1b 100644 --- a/tests/integration/umd-library-name/rslib.config.ts +++ b/tests/integration/umd-library-name/rslib.config.ts @@ -12,4 +12,7 @@ export default defineConfig({ index: './src/index.js', }, }, + output: { + target: 'web', + }, }); diff --git a/website/docs/en/guide/advanced/module-federation.mdx b/website/docs/en/guide/advanced/module-federation.mdx index 2e6627f3f..2d6808ed8 100644 --- a/website/docs/en/guide/advanced/module-federation.mdx +++ b/website/docs/en/guide/advanced/module-federation.mdx @@ -75,6 +75,9 @@ export default defineConfig({ ], }, ], + output: { + target: 'web', + }, plugins: [pluginReact()], }); ``` diff --git a/website/docs/en/guide/advanced/output-compatibility.mdx b/website/docs/en/guide/advanced/output-compatibility.mdx index 06ab09746..973e7317c 100644 --- a/website/docs/en/guide/advanced/output-compatibility.mdx +++ b/website/docs/en/guide/advanced/output-compatibility.mdx @@ -34,7 +34,7 @@ By using [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbui Rslib uses [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill) to provide the Node Polyfill feature. - + Then add the plugin into the plugins field. diff --git a/website/docs/en/guide/basic/output-format.mdx b/website/docs/en/guide/basic/output-format.mdx index a15d037f4..33d330467 100644 --- a/website/docs/en/guide/basic/output-format.mdx +++ b/website/docs/en/guide/basic/output-format.mdx @@ -118,6 +118,9 @@ export default defineConfig({ }, }, ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { diff --git a/website/docs/en/guide/migration/modernjs-module.mdx b/website/docs/en/guide/migration/modernjs-module.mdx index 67dd58fc6..e34558f05 100644 --- a/website/docs/en/guide/migration/modernjs-module.mdx +++ b/website/docs/en/guide/migration/modernjs-module.mdx @@ -110,6 +110,9 @@ import { pluginReact } from '@rsbuild/plugin-react'; export default defineConfig({ //... + output: { + target: 'web', + }, plugins: [pluginReact()], }); ``` diff --git a/website/docs/en/guide/migration/tsup.mdx b/website/docs/en/guide/migration/tsup.mdx index 2f814b6cf..78c95cbba 100644 --- a/website/docs/en/guide/migration/tsup.mdx +++ b/website/docs/en/guide/migration/tsup.mdx @@ -66,16 +66,18 @@ Here is the corresponding Rslib configuration for tsup configuration: ## Platform -For `platform`, tsup defaults to `node` while Rslib defaults to `web` (the same as tsup's `browser`). +For `platform`, tsup defaults to `node` as same as Rslib. -If your target platform is `node`, you can set `output.target` to `node`: +If your target platform is `node`, you do not need to configure it. + +If your target platform is `browser`, you can set `output.target` to `web` in `rslib.config.ts`: ```ts title="rslib.config.ts" import { defineConfig } from '@rslib/core'; export default defineConfig({ output: { - target: 'node', + target: 'web', }, }); ``` diff --git a/website/docs/en/guide/solution/nodejs.mdx b/website/docs/en/guide/solution/nodejs.mdx index e8da9be41..d0b2008d1 100644 --- a/website/docs/en/guide/solution/nodejs.mdx +++ b/website/docs/en/guide/solution/nodejs.mdx @@ -21,7 +21,7 @@ Then select `Node.js` when prompted to "Select template". ## Use Rslib in an existing project -To development an Node.js library, you need to set [target](/config/rsbuild/output#target) to `"node"` in `rslib.config.ts`. This is crucial because when the `target` is set to `"node"`, Rslib automatically adjusts many configurations for Node.js. For example, [output.externals](/config/rsbuild/output#target) will exclude built-in Node.js modules, and [shims](/config/lib/shims) will add a shim for `import.meta.url` in CJS output by default. +Rslib offers seamless support for Node.js projects, allowing you to build Node.js project effortlessly with minimal configuration. For example, in `rsbuild.config.ts`: @@ -47,15 +47,14 @@ export default defineConfig({ }, }, ], - output: { - target: 'node', - }, }); ``` ## Target for Node.js -When [target](/config/rsbuild/output#target) is set to `"node"`, Rslib will automatically adjust the following configurations: +Rslib set [target](/config/rsbuild/output#target) to `"node"` by default, which is different from the default target of Rsbuild. + +Rslib adjusts many configurations for Node.js. For example, [output.externals](/config/rsbuild/output#target) will exclude built-in Node.js modules, and [shims](/config/lib/shims) will add a shim for `import.meta.url` in CJS output by default. ### Externals diff --git a/website/docs/en/guide/solution/react.mdx b/website/docs/en/guide/solution/react.mdx index 472ac3324..f1dbb1248 100644 --- a/website/docs/en/guide/solution/react.mdx +++ b/website/docs/en/guide/solution/react.mdx @@ -21,11 +21,13 @@ Then select `React` when prompted to "Select template". ## Use Rslib in an Existing Project +To develop a React library, you need to set the [target](/config/rsbuild/output#target) to `"web"` in `rslib.config.ts`. This is crucial because Rslib sets the `target` to `"node"` by default, which differs from the default target of Rsbuild. + To compile React (JSX and TSX), you need to register the Rsbuild [React Plugin](https://rsbuild.dev/plugins/list/plugin-react). The plugin will automatically add the necessary configuration for React builds. For example, register in `rslib.config.ts`: -```ts title="rslib.config.ts" {2,8} +```ts title="rslib.config.ts" {2,8-11} import { defineConfig } from '@rslib/core'; import { pluginReact } from '@rsbuild/plugin-react'; @@ -33,6 +35,9 @@ export default defineConfig({ lib: [ // ... ], + output: { + target: 'web', + }, plugins: [pluginReact(/** options here */)], }); ``` @@ -48,7 +53,7 @@ By default, Rsbuild uses the new JSX transform, which is `runtime: 'automatic'`. To change the JSX transform, you can pass the [swcReactOptions](https://rsbuild.dev/plugins/list/plugin-react#swcreactoptionsruntime) option to the React plugin. For example, to use the classic runtime: -```ts title="rslib.config.ts" {10-12} +```ts title="rslib.config.ts" {13-15} import { pluginReact } from '@rsbuild/plugin-react'; import { defineConfig } from '@rslib/core'; @@ -56,6 +61,9 @@ export default defineConfig({ lib: [ // ... ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { @@ -75,7 +83,7 @@ When `runtime` is `'automatic'`, you can specify the import path of the JSX tran For example, when using [Emotion](https://emotion.sh/), you can set `importSource` to `'@emotion/react'`: -```ts title="rslib.config.ts" {10-12} +```ts title="rslib.config.ts" {13-15} import { pluginReact } from '@rsbuild/plugin-react'; import { defineConfig } from '@rslib/core'; @@ -83,6 +91,9 @@ export default defineConfig({ lib: [ // ... ], + output: { + target: 'web', + }, plugins: [ pluginReact({ swcReactOptions: { From b4f52f26a69ea2fbbc411e80e2d754820bcaa175 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Mon, 11 Nov 2024 17:37:45 +0800 Subject: [PATCH 2/3] chore: update --- website/docs/en/guide/migration/tsup.mdx | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/website/docs/en/guide/migration/tsup.mdx b/website/docs/en/guide/migration/tsup.mdx index 78c95cbba..c5cb292f7 100644 --- a/website/docs/en/guide/migration/tsup.mdx +++ b/website/docs/en/guide/migration/tsup.mdx @@ -64,24 +64,6 @@ Here is the corresponding Rslib configuration for tsup configuration: | terserOptions | [output.minify](/config/rsbuild/output) | | tsconfig | [source.tsconfigPath](/config/rsbuild/source) | -## Platform - -For `platform`, tsup defaults to `node` as same as Rslib. - -If your target platform is `node`, you do not need to configure it. - -If your target platform is `browser`, you can set `output.target` to `web` in `rslib.config.ts`: - -```ts title="rslib.config.ts" -import { defineConfig } from '@rslib/core'; - -export default defineConfig({ - output: { - target: 'web', - }, -}); -``` - ## Contents Supplement The current document only covers part of the migration process. If you find suitable content to add, feel free to contribute to the documentation via pull request 🤝. From 1a14add7376a431dd24d891f60b17acc4b41e433 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Mon, 11 Nov 2024 17:59:27 +0800 Subject: [PATCH 3/3] chore: update --- packages/core/src/config.ts | 44 ++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index c5eb1d6ef..2c9114ce4 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -713,8 +713,8 @@ const composeAutoExtensionConfig = ( }; const composeSyntaxConfig = ( + target: RsbuildConfigOutputTarget, syntax?: Syntax, - target: RsbuildConfigOutputTarget = 'node', ): RsbuildConfig => { // Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported. if (syntax) { @@ -942,30 +942,39 @@ const composeDtsConfig = async ( const composeTargetConfig = ( target: RsbuildConfigOutputTarget = 'node', -): RsbuildConfig => { +): { + config: RsbuildConfig; + target: RsbuildConfigOutputTarget; +} => { switch (target) { case 'web': return { - tools: { - rspack: { - target: ['web'], + config: { + tools: { + rspack: { + target: ['web'], + }, }, }, + target: 'web', }; case 'node': return { - tools: { - rspack: { - target: ['node'], + config: { + tools: { + rspack: { + target: ['node'], + }, + }, + output: { + // When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`. + // Simply override the built-in modules to make them external. + // https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L81 + externals: nodeBuiltInModules, + target: 'node', }, }, - output: { - // When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`. - // Simply override the built-in modules to make them external. - // https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L81 - externals: nodeBuiltInModules, - target: 'node', - }, + target: 'node', }; // TODO: Support `neutral` target, however Rsbuild don't list it as an option in the target field. // case 'neutral': @@ -1067,11 +1076,10 @@ async function composeLibRsbuildConfig(config: LibConfig, configPath: string) { cssModulesAuto, bundle, ); - const targetConfig = composeTargetConfig(config.output?.target); - const syntaxConfig = composeSyntaxConfig( - config?.syntax, + const { config: targetConfig, target } = composeTargetConfig( config.output?.target, ); + const syntaxConfig = composeSyntaxConfig(target, config?.syntax); const autoExternalConfig = composeAutoExternalConfig({ autoExternal, pkgJson,