From b481d304c36cc90de670316e8d150aace791f57b Mon Sep 17 00:00:00 2001 From: gaoyuan Date: Sun, 18 Feb 2024 11:48:04 +0800 Subject: [PATCH] chore(uni-builder): set babel-post plugin order to post (#5388) --- .changeset/tasty-humans-train.md | 7 ++++ .../src/rspack/plugins/babel-post.ts | 38 ++++++++++--------- 2 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 .changeset/tasty-humans-train.md diff --git a/.changeset/tasty-humans-train.md b/.changeset/tasty-humans-train.md new file mode 100644 index 000000000000..c8a071e9fceb --- /dev/null +++ b/.changeset/tasty-humans-train.md @@ -0,0 +1,7 @@ +--- +'@modern-js/uni-builder': patch +--- + +chore(uni-builder): set babel-post plugin order to 'post' + +chore(uni-builder): 将 babel-post 顺序调整为 'post' diff --git a/packages/builder/uni-builder/src/rspack/plugins/babel-post.ts b/packages/builder/uni-builder/src/rspack/plugins/babel-post.ts index add98d4f5f54..05dc4be7bbca 100644 --- a/packages/builder/uni-builder/src/rspack/plugins/babel-post.ts +++ b/packages/builder/uni-builder/src/rspack/plugins/babel-post.ts @@ -8,27 +8,29 @@ import { getDefaultBabelOptions } from '@rsbuild/plugin-babel'; export const pluginBabelPost = (): RsbuildPlugin => ({ name: 'uni-builder:babel-post', - pre: ['rsbuild:babel'], - setup(api) { - api.modifyBundlerChain(async (chain, { CHAIN_ID }) => { - if (chain.module.rules.get(CHAIN_ID.RULE.JS)) { - const babelLoaderOptions = chain.module - .rule(CHAIN_ID.RULE.JS) - .use(CHAIN_ID.USE.BABEL) - .get('options'); - const config = api.getNormalizedConfig(); + api.modifyBundlerChain({ + handler: async (chain, { CHAIN_ID }) => { + if (chain.module.rules.get(CHAIN_ID.RULE.JS)) { + const babelLoaderOptions = chain.module + .rule(CHAIN_ID.RULE.JS) + .use(CHAIN_ID.USE.BABEL) + .get('options'); + const config = api.getNormalizedConfig(); - if ( - babelLoaderOptions && - lodash.isEqual( - getDefaultBabelOptions(config.source.decorators), - babelLoaderOptions, - ) - ) { - chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL); + if ( + babelLoaderOptions && + lodash.isEqual( + getDefaultBabelOptions(config.source.decorators), + babelLoaderOptions, + ) + ) { + chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL); + } } - } + }, + // other plugins can modify babel config in modifyBundlerChain 'default order' + order: 'post', }); }, });