Skip to content

Commit

Permalink
Merge branch 'main' into feat/storybook-rsbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy authored Feb 18, 2024
2 parents 7336e5d + 6e50788 commit a8e5299
Show file tree
Hide file tree
Showing 46 changed files with 2,178 additions and 1,915 deletions.
7 changes: 7 additions & 0 deletions .changeset/eleven-pants-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/uni-builder': patch
---

fix(uni-builder): apply babel preset-react when using ts-loader

fix(uni-builder): 使用 ts-loader 时开启 babel preset-react
7 changes: 7 additions & 0 deletions .changeset/kind-apples-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/prod-server': minor
'@modern-js/server-core': minor
---

feat: add server SSR fallback hook
feat: 新增 server SSR 降级 hook 实现
7 changes: 7 additions & 0 deletions .changeset/ninety-apricots-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/uni-builder': patch
---

fix(uni-builder): repeatedly insert babel plugin when using tsLoader in some edge case

fix(uni-builder): 修复在一些边界场景下使用 tsLoader 时会重复添加 babel plugin 的问题
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.3.7",
"@rsbuild/babel-preset": "0.4.0",
"@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.3.7",
"@rsbuild/monorepo-utils": "0.4.0",
"@svgr/webpack": "8.1.0",
"@swc/helpers": "0.5.3",
"deepmerge": "^4.3.1",
Expand Down
37 changes: 19 additions & 18 deletions packages/builder/uni-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@
"@modern-js/server": "workspace:*",
"@modern-js/prod-server": "workspace:*",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
"@rsbuild/babel-preset": "0.3.7",
"@rsbuild/core": "0.3.7",
"@rsbuild/plugin-assets-retry": "0.3.7",
"@rsbuild/plugin-babel": "0.3.7",
"@rsbuild/plugin-check-syntax": "0.3.7",
"@rsbuild/plugin-css-minimizer": "0.3.7",
"@rsbuild/plugin-pug": "0.3.7",
"@rsbuild/plugin-react": "0.3.7",
"@rsbuild/plugin-rem": "0.3.7",
"@rsbuild/plugin-source-build": "0.3.7",
"@rsbuild/plugin-styled-components": "0.3.7",
"@rsbuild/plugin-svgr": "0.3.7",
"@rsbuild/plugin-type-check": "0.3.7",
"@rsbuild/plugin-toml": "0.3.7",
"@rsbuild/plugin-yaml": "0.3.7",
"@rsbuild/shared": "0.3.7",
"@rsbuild/webpack": "0.3.7",
"@rsbuild/babel-preset": "0.4.0",
"@rsbuild/core": "0.4.0",
"@rsbuild/plugin-assets-retry": "0.4.0",
"@rsbuild/plugin-babel": "0.4.0",
"@rsbuild/plugin-check-syntax": "0.4.0",
"@rsbuild/plugin-css-minimizer": "0.4.0",
"@rsbuild/plugin-pug": "0.4.0",
"@rsbuild/plugin-react": "0.4.0",
"@rsbuild/plugin-rem": "0.4.0",
"@rsbuild/plugin-source-build": "0.4.0",
"@rsbuild/plugin-styled-components": "0.4.0",
"@rsbuild/plugin-svgr": "0.4.0",
"@rsbuild/plugin-type-check": "0.4.0",
"@rsbuild/plugin-toml": "0.4.0",
"@rsbuild/plugin-yaml": "0.4.0",
"@rsbuild/shared": "0.4.0",
"@rsbuild/webpack": "0.4.0",
"@swc/helpers": "0.5.3",
"babel-loader": "9.1.3",
"babel-plugin-import": "1.13.5",
Expand All @@ -62,6 +62,7 @@
"html-webpack-plugin": "5.5.3",
"lodash": "^4.17.21",
"postcss-custom-properties": "13.1.5",
"postcss-flexbugs-fixes": "5.0.2",
"postcss-font-variant": "5.0.0",
"postcss-initial": "4.0.1",
"postcss-media-minmax": "5.0.0",
Expand All @@ -76,7 +77,7 @@
},
"devDependencies": {
"@modern-js/builder-plugin-node-polyfill": "workspace:*",
"@rsbuild/plugin-swc": "0.3.7",
"@rsbuild/plugin-swc": "0.4.0",
"@scripts/build": "workspace:*",
"@scripts/vitest-config": "workspace:*",
"@types/lodash": "^4.14.202",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ export const pluginBabelPost = (): RsbuildPlugin => ({
.rule(CHAIN_ID.RULE.JS)
.use(CHAIN_ID.USE.BABEL)
.get('options');
const config = api.getNormalizedConfig();

if (
babelLoaderOptions &&
lodash.isEqual(getDefaultBabelOptions(), babelLoaderOptions)
lodash.isEqual(
getDefaultBabelOptions(config.source.decorators),
babelLoaderOptions,
)
) {
chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL);
}
Expand Down
18 changes: 17 additions & 1 deletion packages/builder/uni-builder/src/shared/parseCommonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { pluginCssMinimizer } from '@rsbuild/plugin-css-minimizer';
import { pluginPostcssLegacy } from './plugins/postcssLegacy';
import { pluginDevtool } from './plugins/devtools';
import { pluginEmitRouteFile } from './plugins/emitRouteFile';
import { pluginAntd } from './plugins/antd';
import { pluginArco } from './plugins/arco';

const GLOBAL_CSS_REGEX = /\.global\.\w+$/;

Expand Down Expand Up @@ -117,6 +119,8 @@ export async function parseCommonConfig(
plugins: [...plugins] = [],
performance: { ...performanceConfig } = {},
output: {
disableFilenameHash,
enableLatestDecorators,
cssModuleLocalIdentName,
enableInlineScripts,
disableCssExtract,
Expand Down Expand Up @@ -167,7 +171,13 @@ export async function parseCommonConfig(
security: securityConfig,
};

const { dev = {}, html = {}, output = {} } = rsbuildConfig;
const { dev = {}, html = {}, output = {}, source = {} } = rsbuildConfig;

if (enableLatestDecorators) {
source.decorators = {
version: '2022-03',
};
}

if (cssModuleLocalIdentName) {
output.cssModules ||= {};
Expand Down Expand Up @@ -219,6 +229,10 @@ export async function parseCommonConfig(
output.inlineStyles = enableInlineStyles;
}

if (disableFilenameHash !== undefined) {
output.filenameHash = !disableFilenameHash;
}

const extraConfig: RsbuildConfig = {};
extraConfig.html ||= {};

Expand Down Expand Up @@ -330,6 +344,8 @@ export async function parseCommonConfig(
pluginEmitRouteFile(),
pluginToml(),
pluginYaml(),
pluginAntd(),
pluginArco(),
];

if (checkSyntax) {
Expand Down
48 changes: 48 additions & 0 deletions packages/builder/uni-builder/src/shared/plugins/antd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { isServerTarget, type RsbuildPlugin } from '@rsbuild/shared';

const getAntdMajorVersion = (appDirectory: string) => {
try {
const pkgJsonPath = require.resolve('antd/package.json', {
paths: [appDirectory],
});
const { version } = require(pkgJsonPath);
return Number(version.split('.')[0]);
} catch (err) {
return null;
}
};

export const pluginAntd = (): RsbuildPlugin => ({
name: 'uni-builder:antd',
setup(api) {
api.modifyRsbuildConfig(rsbuildConfig => {
rsbuildConfig.source ??= {};

if (
rsbuildConfig.source.transformImport === false ||
rsbuildConfig.source.transformImport?.some(
item => item.libraryName === 'antd',
)
) {
return;
}

const antdMajorVersion = getAntdMajorVersion(api.context.rootPath);
// antd >= v5 no longer need babel-plugin-import
// see: https://ant.design/docs/react/migration-v5#remove-babel-plugin-import
if (antdMajorVersion && antdMajorVersion < 5) {
rsbuildConfig.source ??= {};
rsbuildConfig.source.transformImport = [
...(rsbuildConfig.source.transformImport || []),
{
libraryName: 'antd',
libraryDirectory: isServerTarget(api.context.targets)
? 'lib'
: 'es',
style: true,
},
];
}
});
},
});
44 changes: 44 additions & 0 deletions packages/builder/uni-builder/src/shared/plugins/arco.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { isServerTarget, type RsbuildPlugin } from '@rsbuild/shared';
import { isPackageInstalled } from '@modern-js/utils';

export const pluginArco = (): RsbuildPlugin => ({
name: 'uni-builder:arco',

setup(api) {
const ARCO_NAME = '@arco-design/web-react';
const ARCO_ICON = `${ARCO_NAME}/icon`;

api.modifyRsbuildConfig(rsbuildConfig => {
const { transformImport = [] } = rsbuildConfig.source || {};

if (
transformImport === false ||
!isPackageInstalled(ARCO_NAME, api.context.rootPath)
) {
return;
}

const isUseSSR = isServerTarget(api.context.targets);

if (!transformImport?.some(item => item.libraryName === ARCO_NAME)) {
transformImport.push({
libraryName: ARCO_NAME,
libraryDirectory: isUseSSR ? 'lib' : 'es',
camelToDashComponentName: false,
style: true,
});
}

if (!transformImport?.some(item => item.libraryName === ARCO_ICON)) {
transformImport.push({
libraryName: ARCO_ICON,
libraryDirectory: isUseSSR ? 'react-icon-cjs' : 'react-icon',
camelToDashComponentName: false,
});
}

rsbuildConfig.source ||= {};
rsbuildConfig.source.transformImport = transformImport;
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const pluginPostcssLegacy = (
const enableCssMinify = !enableExtractCSS && isProd;

const plugins = [
require('postcss-flexbugs-fixes'),
!cssSupport.customProperties && require('postcss-custom-properties'),
!cssSupport.initial && require('postcss-initial'),
!cssSupport.pageBreak && require('postcss-page-break'),
Expand Down
8 changes: 2 additions & 6 deletions packages/builder/uni-builder/src/shared/plugins/splitChunk.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
isPlainObject,
isPackageInstalled,
createCacheGroups,
type SplitChunks,
} from '@rsbuild/shared';
import { createCacheGroups, type SplitChunks } from '@rsbuild/shared';
import { isPlainObject, isPackageInstalled } from '@modern-js/utils';
import type { RsbuildPlugin } from '@rsbuild/core';

export const pluginSplitChunks = (): RsbuildPlugin => ({
Expand Down
8 changes: 8 additions & 0 deletions packages/builder/uni-builder/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ export type UniBuilderExtraConfig = {
resolveExtensionPrefix?: string | Partial<Record<RsbuildTarget, string>>;
};
output?: {
/**
* @deprecated use `output.filenameHash` instead
*/
disableFilenameHash?: boolean;
/**
* @deprecated use `source.decorators` instead
*/
enableLatestDecorators?: boolean;
/**
* @deprecated use `output.cssModules.localIdentName` instead
*/
Expand Down
Loading

0 comments on commit a8e5299

Please sign in to comment.