babel-plugin-import不生效的问题
2017-05-19 21:20
363 查看
转载自:点击打开链接
问题描述:
使用create-React-app生成项目,然后eject,然后安装了antd和babel-plugin-import依赖包,按antd官网的说明在babelrc里面加了配置:
{
"plugins": [
["import", { libraryName: "antd", style: "css" }]
]
}
大概2016年10月份按这个流程构建的项目,是没有任何问题的,但是今天重新构建一遍之后,发现babel-plugin-import并没有生效,浏览器还是警告:You are using a whole pachage of antd,而且antd的组件都没有样式
解决:
在webpack配置文件的loader配置里面来配置antd,即:
loaders: [
...
{
text: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
query: {
cacheDirectory: true,
plugins: [["import", { libraryName: "antd", style: "css" }]]
}
},
...
]
问题解决。
即,配置babel-plugin-import有两种方式,可以在babelrc里面,也可以在webpack里面,但是当前版本下在babelrc里面配置就会出现不生效的问题。
问题描述:
使用create-React-app生成项目,然后eject,然后安装了antd和babel-plugin-import依赖包,按antd官网的说明在babelrc里面加了配置:
{
"plugins": [
["import", { libraryName: "antd", style: "css" }]
]
}
大概2016年10月份按这个流程构建的项目,是没有任何问题的,但是今天重新构建一遍之后,发现babel-plugin-import并没有生效,浏览器还是警告:You are using a whole pachage of antd,而且antd的组件都没有样式
解决:
在webpack配置文件的loader配置里面来配置antd,即:
loaders: [
...
{
text: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
query: {
cacheDirectory: true,
plugins: [["import", { libraryName: "antd", style: "css" }]]
}
},
...
]
问题解决。
即,配置babel-plugin-import有两种方式,可以在babelrc里面,也可以在webpack里面,但是当前版本下在babelrc里面配置就会出现不生效的问题。
相关文章推荐
- babel-plugin-import不生效的问题
- babel-plugin-import
- IntelJ idea下lombok 不生效的问题(@Builder等注解不生效的问题)解决,lombok Plugin插件安装
- 组件库按需加载 借助babel-plugin-import实现
- babel引起的import无法正常转换成es5的问题
- IntelJ idea下lombok 不生效的问题(@Builder等注解不生效的问题)解决,lombok Plugin插件安装
- react中使用AntDesign库 --- babel-plugin-import 配置
- [转] 组件库按需加载 借助babel-plugin-import实现
- [Django]ImportError:cannot import name debug问题
- Data Protector Import问题
- 问题关于: Unable to find the mojo 'org.appfuse:maven-warpath-plugin:1.0-m5:add-classes' in the plugin 'org.appfuse:maven-warpath-pl
- Eclipse 3.4 + Tomcat Plugin + Tomcat 6 "DevLoader" 问题解决办法
- 调试用Python C API 写的程序问题还真多,关于import搜索路径的,复制过来,以防忘记
- maven中构建私服器, 上传jar/plugin 到FTP 上传出现问题
- 使用maven-jetty-plugin启动JBoss是遇到的问题。
- Eclipse3.1使用tk.eclipse.plugin.struts的问题
- drools加入到eclipse plugin里的问题
- 高分求助pb importString()函数问题
- 问题:I have a WSDL file and tried the Eclipse(Eclipse3.2) plugin:WSDL2Java(AXIS2).
- import static net.mindview.util.Print.*的傻瓜问题