按需加载
如果您使用了 babel,借助插件 babel-plugin-import 可以实现按需加载模块,减少文件体积。
yarn add babel-plugin-import -D
1
npm i babel-plugin-import -D
1
// Make sure to add code blocks to your code group
- 修改文件 .babelrc 或 babel.config.js
{
"plugins": [
[
"import",
{
"libraryName": "sfutils",
"camel2DashComponentName": false
},
"sfutils"
]
]
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
module.exports = {
presets: ...,
env: {
...
},
plugins: [
// 注意⚠️:写在这
[
'import',
{
libraryName: 'sf-utils2',
camel2DashComponentName: false
},
'sf-utils2'
]
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Make sure to add code blocks to your code group
- 图片

上次更新: 2023/06/24, 19:35:48