Skip to content

Commit

Permalink
chore(uni-builder): set babel-post plugin order to post (#5388)
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy authored Feb 18, 2024
1 parent 6e50788 commit b481d30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .changeset/tasty-humans-train.md
Original file line number Diff line number Diff line change
@@ -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'
38 changes: 20 additions & 18 deletions packages/builder/uni-builder/src/rspack/plugins/babel-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
},
});

0 comments on commit b481d30

Please sign in to comment.