-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(antd/next): fix Editable is not work with babel-import-plugin #1645
- Loading branch information
Showing
6 changed files
with
109 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,34 +7,49 @@ | |
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
|
||
or | ||
|
||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
||
#### Plugin Configuration | ||
|
||
Modify `.umirc.js` or `.umirc.ts` | ||
|
||
```js | ||
export default { | ||
extraBabelPlugins: [['babel-plugin-import', {"libraryName": "@formily/antd", "libraryDirectory": "lib"}]], | ||
}; | ||
extraBabelPlugins: [ | ||
[ | ||
'babel-plugin-import', | ||
{ libraryName: 'antd', libraryDirectory: 'lib', style: true }, | ||
], | ||
[ | ||
'babel-plugin-import', | ||
{ libraryName: '@formily/antd', libraryDirectory: 'lib', style: true }, | ||
], | ||
], | ||
} | ||
``` | ||
|
||
## Based on Create-react-app Development | ||
|
||
First, we need to customize the default configuration of `create-react-app`, here we use [react-app-rewired](https://github.com/timarney/react-app-rewired) (A community solution for custom configuration of `create-react-app`) | ||
Introduce `react-app-rewired` and modify the startup configuration in `package.json`. Due to the new [[email protected]](https://github.com/timarney/react-app-rewired#alternatives) version, you also need to install [customize-cra](https://github.com/arackaf/customize-cra). | ||
Introduce `react-app-rewired` and modify the startup configuration in `package.json`. Due to the new [[email protected]](https://github.com/timarney/react-app-rewired#alternatives) version, you also need to install [customize-cra](https://github.com/arackaf/customize-cra). | ||
|
||
```shell | ||
$ npm install react-app-rewired customize-cra --save-dev | ||
``` | ||
|
||
or | ||
|
||
```shell | ||
$ yarn add react-app-rewired customize-cra --dev | ||
``` | ||
|
||
modify `package.json` | ||
|
||
```diff | ||
"scripts": { | ||
- "start": "react-scripts start", | ||
|
@@ -45,20 +60,24 @@ modify `package.json` | |
+ "test": "react-app-rewired test", | ||
} | ||
``` | ||
Then create a `config-overrides.js` in the project root directory to modify the default configuration. | ||
|
||
Then create a `config-overrides.js` in the project root directory to modify the default configuration. | ||
|
||
```js | ||
module.exports = function override(config, env) { | ||
// do stuff with the webpack config... | ||
return config; | ||
}; | ||
return config | ||
} | ||
``` | ||
|
||
#### Install babel-plugin-import | ||
|
||
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
|
||
or | ||
|
||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
@@ -74,21 +93,28 @@ modify `config-overrides.js` | |
- }; | ||
+ module.exports = override( | ||
+ fixBabelImports('import', { | ||
+ libraryName: 'antd', | ||
+ libraryDirectory: 'lib', | ||
+ style: true | ||
+ }), | ||
+ fixBabelImports('import', { | ||
+ libraryName: '@formily/antd', | ||
+ libraryDirectory: 'lib' | ||
+ libraryDirectory: 'lib', | ||
+ style: true | ||
+ }), | ||
+ ); | ||
``` | ||
|
||
|
||
## Use in Webpack | ||
|
||
#### Install babel-plugin-import | ||
|
||
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
|
||
or | ||
|
||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
@@ -98,10 +124,24 @@ Modify `.babelrc` or babel-loader | |
```json | ||
{ | ||
"plugins": [ | ||
["import", { "libraryName": "@formily/antd", "libraryDirectory": "lib"}] | ||
[ | ||
"import", | ||
{ | ||
"libraryName": "antd", | ||
"libraryDirectory": "lib", | ||
"style": true | ||
} | ||
], | ||
[ | ||
"import", | ||
{ | ||
"libraryName": "@formily/antd", | ||
"libraryDirectory": "lib", | ||
"style": true | ||
} | ||
] | ||
] | ||
} | ||
``` | ||
|
||
For more configuration, please refer to [babel-plugin-import](https://github.com/ant-design/babel-plugin-import) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,55 @@ | ||
# 按需打包 | ||
|
||
## 基于Umi开发 | ||
## 基于 Umi 开发 | ||
|
||
#### 安装 `babel-plugin-import` | ||
|
||
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
|
||
或者 | ||
|
||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
||
#### 插件配置 | ||
|
||
修改 `.umirc.js`或 `.umirc.ts` | ||
|
||
```js | ||
export default { | ||
extraBabelPlugins: [['babel-plugin-import', {"libraryName": "@formily/antd", "libraryDirectory": "lib"}]], | ||
}; | ||
extraBabelPlugins: [ | ||
[ | ||
'babel-plugin-import', | ||
{ libraryName: 'antd', libraryDirectory: 'lib', style: true }, | ||
], | ||
[ | ||
'babel-plugin-import', | ||
{ libraryName: '@formily/antd', libraryDirectory: 'lib', style: true }, | ||
], | ||
], | ||
} | ||
``` | ||
|
||
## 基于create-react-app开发 | ||
## 基于 create-react-app 开发 | ||
|
||
首先我们需要对`create-react-app`的默认配置进行自定义,这里我们使用 [react-app-rewired](https://github.com/timarney/react-app-rewired) (一个对 `create-react-app` 进行自定义配置的社区解决方案)。 | ||
首先我们需要对`create-react-app`的默认配置进行自定义,这里我们使用 [react-app-rewired](https://github.com/timarney/react-app-rewired) (一个对 `create-react-app` 进行自定义配置的社区解决方案)。 | ||
引入 `react-app-rewired` 并修改 `package.json` 里的启动配置。由于新的 [[email protected]](https://github.com/timarney/react-app-rewired#alternatives) 版本的关系,你还需要安装 [customize-cra](https://github.com/arackaf/customize-cra)。 | ||
|
||
```shell | ||
$ npm install react-app-rewired customize-cra --save-dev | ||
``` | ||
|
||
或者 | ||
|
||
```shell | ||
$ yarn add react-app-rewired customize-cra --dev | ||
``` | ||
|
||
修改 `package.json` | ||
|
||
```diff | ||
"scripts": { | ||
- "start": "react-scripts start", | ||
|
@@ -45,20 +60,24 @@ $ yarn add react-app-rewired customize-cra --dev | |
+ "test": "react-app-rewired test", | ||
} | ||
``` | ||
|
||
然后在项目根目录创建一个 `config-overrides.js` 用于修改默认配置。 | ||
|
||
```js | ||
module.exports = function override(config, env) { | ||
// do stuff with the webpack config... | ||
return config; | ||
}; | ||
return config | ||
} | ||
``` | ||
|
||
#### 安装 babel-plugin-import | ||
|
||
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
|
||
或者 | ||
|
||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
@@ -74,21 +93,28 @@ yarn add babel-plugin-import --dev | |
- }; | ||
+ module.exports = override( | ||
+ fixBabelImports('import', { | ||
+ libraryName: 'antd', | ||
+ libraryDirectory: 'lib', | ||
+ style: true | ||
+ }), | ||
+ fixBabelImports('import', { | ||
+ libraryName: '@formily/antd', | ||
+ libraryDirectory: 'lib' | ||
+ libraryDirectory: 'lib', | ||
+ style: true | ||
+ }), | ||
+ ); | ||
``` | ||
|
||
|
||
## 在Webpack中使用 | ||
## 在 Webpack 中使用 | ||
|
||
#### 安装 babel-plugin-import | ||
|
||
```shell | ||
npm install babel-plugin-import --save-dev | ||
``` | ||
|
||
或者 | ||
|
||
```shell | ||
yarn add babel-plugin-import --dev | ||
``` | ||
|
@@ -98,7 +124,22 @@ yarn add babel-plugin-import --dev | |
```json | ||
{ | ||
"plugins": [ | ||
["import", { "libraryName": "@formily/antd", "libraryDirectory": "lib"}] | ||
[ | ||
"import", | ||
{ | ||
"libraryName": "antd", | ||
"libraryDirectory": "lib", | ||
"style": true | ||
} | ||
], | ||
[ | ||
"import", | ||
{ | ||
"libraryName": "@formily/antd", | ||
"libraryDirectory": "lib", | ||
"style": true | ||
} | ||
] | ||
] | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,3 +187,5 @@ Editable.Popover = observer((props) => { | |
</Popover> | ||
) | ||
}) | ||
|
||
export default Editable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters