Skip to content

Commit

Permalink
chore: bump rsbuild to 0.2.17 & update rspack babel plugin (#5189)
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy authored Jan 5, 2024
1 parent 78e2722 commit 4c4b2b0
Show file tree
Hide file tree
Showing 16 changed files with 442 additions and 133 deletions.
7 changes: 7 additions & 0 deletions .changeset/long-shoes-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/uni-builder': patch
---

chore(deps): bump rsbuild to 0.2.17

chore(deps): 升级 rsbuild 到 0.2.17
2 changes: 1 addition & 1 deletion packages/builder/builder-webpack-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"@modern-js/types": "workspace:*",
"@modern-js/utils": "workspace:*",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
"@rsbuild/babel-preset": "0.2.15",
"@rsbuild/babel-preset": "0.2.17",
"@swc/helpers": "0.5.3",
"babel-plugin-import": "1.13.5",
"babel-plugin-styled-components": "1.13.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"dependencies": {
"@modern-js/builder-shared": "workspace:*",
"@modern-js/utils": "workspace:*",
"@rsbuild/monorepo-utils": "0.2.15",
"@rsbuild/monorepo-utils": "0.2.17",
"@svgr/webpack": "8.1.0",
"@swc/helpers": "0.5.3",
"deepmerge": "^4.3.1",
Expand Down
32 changes: 16 additions & 16 deletions packages/builder/uni-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@
"@modern-js/server": "workspace:*",
"@modern-js/prod-server": "workspace:*",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
"@rsbuild/babel-preset": "0.2.15",
"@rsbuild/core": "0.2.15",
"@rsbuild/plugin-assets-retry": "0.2.15",
"@rsbuild/plugin-babel": "0.2.15",
"@rsbuild/plugin-check-syntax": "0.2.15",
"@rsbuild/plugin-css-minimizer": "0.2.15",
"@rsbuild/plugin-pug": "0.2.15",
"@rsbuild/plugin-react": "0.2.15",
"@rsbuild/plugin-rem": "0.2.15",
"@rsbuild/plugin-source-build": "0.2.15",
"@rsbuild/plugin-styled-components": "0.2.15",
"@rsbuild/plugin-svgr": "0.2.15",
"@rsbuild/plugin-type-check": "0.2.15",
"@rsbuild/shared": "0.2.15",
"@rsbuild/webpack": "0.2.15",
"@rsbuild/babel-preset": "0.2.17",
"@rsbuild/core": "0.2.17",
"@rsbuild/plugin-assets-retry": "0.2.17",
"@rsbuild/plugin-babel": "0.2.17",
"@rsbuild/plugin-check-syntax": "0.2.17",
"@rsbuild/plugin-css-minimizer": "0.2.17",
"@rsbuild/plugin-pug": "0.2.17",
"@rsbuild/plugin-react": "0.2.17",
"@rsbuild/plugin-rem": "0.2.17",
"@rsbuild/plugin-source-build": "0.2.17",
"@rsbuild/plugin-styled-components": "0.2.17",
"@rsbuild/plugin-svgr": "0.2.17",
"@rsbuild/plugin-type-check": "0.2.17",
"@rsbuild/shared": "0.2.17",
"@rsbuild/webpack": "0.2.17",
"@swc/helpers": "0.5.3",
"babel-loader": "9.1.3",
"babel-plugin-import": "1.13.5",
Expand All @@ -74,7 +74,7 @@
},
"devDependencies": {
"@modern-js/builder-plugin-node-polyfill": "workspace:*",
"@rsbuild/plugin-swc": "0.2.15",
"@rsbuild/plugin-swc": "0.2.17",
"@scripts/build": "workspace:*",
"@scripts/vitest-config": "workspace:*",
"@types/lodash": "^4.14.202",
Expand Down
2 changes: 2 additions & 0 deletions packages/builder/uni-builder/src/rspack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export async function parseConfig(

if (uniBuilderConfig.tools?.babel) {
const { pluginBabel } = await import('@rsbuild/plugin-babel');
const { pluginBabelPost } = await import('./plugins/babel-post');
rsbuildPlugins.push(
pluginBabel({
babelLoaderOptions: uniBuilderConfig.tools?.babel,
}),
pluginBabelPost(),
);
}

Expand Down
30 changes: 30 additions & 0 deletions packages/builder/uni-builder/src/rspack/plugins/babel-post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import lodash from 'lodash';
import { type RsbuildPlugin } from '@rsbuild/shared';
import { getDefaultBabelOptions } from '@rsbuild/plugin-babel';

/**
* should not set babel-loader when babel config not modified
*/
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');

if (
babelLoaderOptions &&
lodash.isEqual(getDefaultBabelOptions(), babelLoaderOptions)
) {
chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL);
}
}
});
},
});
2 changes: 2 additions & 0 deletions packages/builder/uni-builder/src/shared/plugins/splitChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const pluginSplitChunks = (): RsbuildPlugin => ({

chain.optimization.splitChunks({
...currentConfig,
// rspack chunks type mismatch with webpack
// @ts-expect-error
cacheGroups: {
...(currentConfig as Exclude<SplitChunks, false>).cacheGroups,
...createCacheGroups(groups),
Expand Down
206 changes: 206 additions & 0 deletions packages/builder/uni-builder/tests/__snapshots__/babel.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,211 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`plugin-babel (rspack mode) > should not set babel-loader when babel config not modified 1`] = `
[
{
"resolve": {
"fullySpecified": false,
},
"test": /\\\\\\.m\\?js/,
},
{
"include": [
{
"and": [
"",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
"test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "builtin:swc-loader",
"options": {
"env": {
"coreJs": "3.32",
"mode": "entry",
"targets": [
"> 0.01%",
"not dead",
"not op_mini all",
],
},
"isModule": "unknown",
"jsc": {
"externalHelpers": true,
"parser": {
"decorators": true,
"syntax": "typescript",
"tsx": true,
},
"preserveAllComments": true,
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"development": true,
"refresh": true,
"runtime": "automatic",
},
},
},
"rspackExperiments": {
"import": [
{
"libraryDirectory": "es",
"libraryName": "antd",
"style": true,
},
{
"camelToDashComponentName": false,
"libraryDirectory": "es",
"libraryName": "@arco-design/web-react",
"style": true,
},
{
"camelToDashComponentName": false,
"libraryDirectory": "react-icon",
"libraryName": "@arco-design/web-react/icon",
},
],
"styledComponents": {
"displayName": true,
"pure": false,
"ssr": false,
"transpileTemplateLiterals": true,
},
},
"sourceMaps": true,
},
},
],
},
]
`;

exports[`plugin-babel (rspack mode) > should set babel-loader when babel config modified 1`] = `
[
{
"resolve": {
"fullySpecified": false,
},
"test": /\\\\\\.m\\?js/,
},
{
"include": [
{
"and": [
"",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
"test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "builtin:swc-loader",
"options": {
"env": {
"coreJs": "3.32",
"mode": "entry",
"targets": [
"> 0.01%",
"not dead",
"not op_mini all",
],
},
"isModule": "unknown",
"jsc": {
"externalHelpers": true,
"parser": {
"decorators": true,
"syntax": "typescript",
"tsx": true,
},
"preserveAllComments": true,
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"development": true,
"refresh": true,
"runtime": "automatic",
},
},
},
"rspackExperiments": {
"import": [
{
"libraryDirectory": "es",
"libraryName": "antd",
"style": true,
},
{
"camelToDashComponentName": false,
"libraryDirectory": "es",
"libraryName": "@arco-design/web-react",
"style": true,
},
{
"camelToDashComponentName": false,
"libraryDirectory": "react-icon",
"libraryName": "@arco-design/web-react/icon",
},
],
"styledComponents": {
"displayName": true,
"pure": false,
"ssr": false,
"transpileTemplateLiterals": true,
},
},
"sourceMaps": true,
},
},
{
"loader": "<WORKSPACE>/node_modules/<PNPM_INNER>/@rsbuild/plugin-babel/compiled/babel-loader/index.js",
"options": {
"babelrc": false,
"compact": false,
"configFile": false,
"plugins": [
[
"babel-plugin-import",
{
"libraryDirectory": "es",
"libraryName": "xxx-components",
"style": true,
},
],
],
"presets": [
[
"<WORKSPACE>/node_modules/<PNPM_INNER>/@babel/preset-typescript/lib/index.js",
{
"allExtensions": true,
"allowDeclareFields": true,
"allowNamespaces": true,
"isTSX": true,
"optimizeConstEnums": true,
},
],
],
},
},
],
},
]
`;

exports[`plugin-babel > should add core-js-entry when output.polyfill is entry 1`] = `
[
{
Expand Down
Loading

0 comments on commit 4c4b2b0

Please sign in to comment.