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

feat: 添加 react 代码性能优化转换 #261

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

node scripts/check-deps.mjs
lerna run --exclude-dependents --since HEAD lint
npx lerna run --exclude-dependents --since HEAD lint
2 changes: 2 additions & 0 deletions packages/config-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"@babel/plugin-proposal-throw-expressions": "^7.16.5",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-react-constant-elements": "^7.16.7",
"@babel/plugin-transform-react-inline-elements": "^7.16.7",
"@babel/preset-env": "^7.16.5",
"@babel/preset-react": "^7.16.5",
"@babel/preset-typescript": "^7.16.5",
Expand Down
8 changes: 8 additions & 0 deletions packages/config-babel/src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {PluginItem, TransformOptions} from '@babel/core';
import pluginLodash from 'babel-plugin-lodash';
import pluginReactConstantElement from '@babel/plugin-transform-react-constant-elements';
import pluginReactInlineElement from '@babel/plugin-transform-react-inline-elements';
import {compact} from '@reskript/core';
import addReactDisplayName from '@reskript/babel-plugin-add-react-display-name';
import {shouldEnable} from './utils.js';
Expand Down Expand Up @@ -28,6 +30,12 @@ export default (options: BabelConfigOptionsFilled): TransformOptions => {
id: ['lodash', 'lodash-decorators'],
},
],
// https://babeljs.io/docs/en/babel-plugin-transform-react-constant-elements
// https://github.com/facebook/react/issues/3226
pluginReactConstantElement,
// https://babeljs.io/docs/en/babel-plugin-transform-react-inline-elements
// https://github.com/facebook/react/issues/3228
pluginReactInlineElement,
];

return {
Expand Down
14 changes: 14 additions & 0 deletions packages/config-babel/src/types/babel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ declare module '@babel/plugin-syntax-import-meta' {
export default target;
}

declare module '@babel/plugin-transform-react-constant-elements' {
import {PluginTarget} from '@babel/core';

const target: PluginTarget;
export default target;
}

declare module '@babel/plugin-transform-react-inline-elements' {
import {PluginTarget} from '@babel/core';

const target: PluginTarget;
export default target;
}

declare module 'babel-plugin-styled-components' {
import {PluginTarget} from '@babel/core';

Expand Down
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.