2
我使用babel-plugin-import
插件导入antd包。但是,我收到整个包被导入的警告。部分导入的antd包不能正常工作
您使用antd的全包,请使用 https://www.npmjs.com/package/babel-plugin-import减少应用程序捆绑 大小。
我给JSX的WebPack配置如下:
{
test: /\.jsx$/,
loader: 'babel-loader',
exclude: [nodeModulesDir],
options: {
cacheDirectory: true,
plugins: [
'transform-decorators-legacy',
'add-module-exports',
["import", { "libraryName": "antd", "style": true }],
["react-transform", {
transforms: [
{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module']
}
]
}]
],
presets: ['es2015', 'stage-0', 'react']
}
},
出于某种原因,整个antd束被导入。
你是如何导入antd组件的? – wuxiandiejia
通常的方法:'从'antd''导入{Button} – vijayst
我发现一个注释'babel-plugin-import文件将无法正常工作,如果您在[webpack config vendor。 ](https://github.com/ant-design/babel-plugin-import#note)。 – wuxiandiejia