关于 ant-design/babel-plugin-import 按需加载的 babel polyfill疑问。
问题
在项目新建的时候引用了babel-plugin-import
的antd按需加载plugin,已配置好相关的babel-preset,但是在实际webpack
输出的bundle内发现,按需加载的antd源码并没有被polyfill。
尝试方法(均无效)
- 将
ant-design-vue
提升到devDependencies
- 将
ant-design-vue
的包include到babel-loader
中
环境
babel-loader
配置如下:
{
test: /(\.jsx|\.js)$/,
loader: "babel-loader",
// exclude: path.resolve(__dirname, "node_modules")
include: [path.resolve(__dirname, "xxx/src"), path.resolve(__dirname, "node_modules/ant-design-vue")]
}
.babelrc
配置如下:
{
"presets": [
[
"@babel/preset-env",
{
"modules": "commonjs",
"targets": [
"> 1%",
"last 2 versions",
"ie 11"
],
"useBuiltIns": "usage",
"corejs": 3
}
]
],
"plugins": [
[
"import",
{
"libraryName": "ant-design-vue",
"style": true
}
]
]
}
...
{
"dependencies": {
"art-template": "^4.12.2",
"core-js": "^3.10.1",
"less": "^3.13.1",
"vue": "^2.6.12"
},
"devDependencies": {
"@babel/core": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"ant-design-vue": "^1.7.4",
"art-template-loader": "^1.4.3",
"babel-loader": "^8.2.2",
"babel-plugin-import": "^1.13.3",
"css-loader": "^5.2.2",
"less-loader": "^7.3.0",
"mini-css-extract-plugin": "^1.5.0",
"mocker-api": "^2.7.4",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"postcss": "^8.2.10",
"postcss-loader": "^4.2.0",
"postcss-preset-env": "^6.7.0",
"url-loader": "^0.6.2",
"vue-loader": "^15.9.6",
"vue-template-compiler": "^2.6.12",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.2"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论