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

perf: skip calculation if browserslist is default value #2882

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Changes from all 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
17 changes: 15 additions & 2 deletions packages/core/src/plugins/target.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import * as toESVersion from 'browserslist-to-es-version';
import { DEFAULT_WEB_BROWSERSLIST } from '../constants';
import type { RsbuildPlugin } from '../types';

const getESVersion = async (browserslist: string[]) => {
const { browserslistToESVersion } = await import(
'browserslist-to-es-version'
);

// skip calculation if the browserslist is the default value
if (browserslist.join(',') === DEFAULT_WEB_BROWSERSLIST.join(',')) {
return 2017;
}

return browserslistToESVersion(browserslist);
};

export const pluginTarget = (): RsbuildPlugin => ({
name: 'rsbuild:target',

Expand All @@ -14,7 +27,7 @@ export const pluginTarget = (): RsbuildPlugin => ({
}

const { browserslist } = environment;
const esVersion = toESVersion.browserslistToESVersion(browserslist);
const esVersion = await getESVersion(browserslist);

if (target === 'web-worker') {
chain.target(['webworker', `es${esVersion}`]);
Expand Down
Loading