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