Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: target default to node #398

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions examples/express-plugin/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ export default defineConfig({
},
},
],
output: {
target: 'node',
},
});
3 changes: 3 additions & 0 deletions examples/module-federation/mf-react-component/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ export default defineConfig({
],
},
],
output: {
target: 'web',
},
plugins: [pluginReact()],
});
3 changes: 3 additions & 0 deletions examples/react-component-bundle-false/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default defineConfig({
},
},
],
output: {
target: 'web',
},
plugins: [
pluginReact({
swcReactOptions: {
Expand Down
3 changes: 3 additions & 0 deletions examples/react-component-bundle/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default defineConfig({
},
},
],
output: {
target: 'web',
},
plugins: [
pluginReact({
swcReactOptions: {
Expand Down
3 changes: 3 additions & 0 deletions examples/react-component-umd/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default defineConfig({
},
},
],
output: {
target: 'web',
},
plugins: [
pluginReact({
swcReactOptions: {
Expand Down
1 change: 1 addition & 0 deletions packages/core/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineConfig({
},
},
output: {
// TODO: Remove this after bumping Rslib
target: 'node',
externals: {
picocolors: '../compiled/picocolors/index.js',
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ export async function createConstantRsbuildConfig(): Promise<RsbuildConfig> {
},
},
output: {
target: 'node',
filenameHash: false,
distPath: {
js: './',
Expand Down Expand Up @@ -558,7 +559,6 @@ const composeFormatConfig = ({
},
output: {
asyncChunks: false,

library: umdName
? {
type: 'umd',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -941,7 +941,7 @@ const composeDtsConfig = async (
};

const composeTargetConfig = (
target: RsbuildConfigOutputTarget = 'web',
target: RsbuildConfigOutputTarget = 'node',
): RsbuildConfig => {
Timeless0911 marked this conversation as resolved.
Show resolved Hide resolved
switch (target) {
case 'web':
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/utils/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -195,7 +191,7 @@ export function transformSyntaxToRspackTarget(

export function transformSyntaxToBrowserslist(
syntax: Syntax,
target?: NonNullable<RsbuildConfig['output']>['target'],
target: NonNullable<RsbuildConfig['output']>['target'],
): NonNullable<NonNullable<RsbuildConfig['output']>['overrideBrowserslist']> {
const handleSyntaxItem = (
syntaxItem: EcmaScriptVersion | string,
Expand Down
199 changes: 178 additions & 21 deletions packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down Expand Up @@ -141,7 +192,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
[Function],
{
"target": [
"web",
"node",
],
},
{
Expand Down Expand Up @@ -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",
},
Expand All @@ -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": {
Expand Down Expand Up @@ -298,7 +402,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
[Function],
{
"target": [
"web",
"node",
],
},
{
Expand Down Expand Up @@ -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",
},
Expand All @@ -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": {
Expand Down Expand Up @@ -437,7 +594,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
[Function],
{
"target": [
"web",
"node",
],
},
{
Expand Down
6 changes: 0 additions & 6 deletions packages/core/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ export default defineConfig({
syntax: 'es2021',
},
],
output: { target: 'node' },
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ export default defineConfig({
syntax: 'es2021',
},
],
output: { target: 'node' },
});
Loading
Loading