webpack2 ant-design-mobile error
See original GitHub issue本地环境
- antd-mobile 版本: “antd-mobile”: “^0.9.8”,
- 操作系统及其版本: windows10 node: 7.0.0
- 浏览器及其版本: chrome55
你做了什么?
import 'antd-mobile/lib/button/style';
import Button from 'antd-mobile/lib/button';
import React, {Component} from 'react'
class AntNavBar extends Component {
render () {
return (
<div>
<Button>Start</Button>
</div>
)
}
}
export default AntNavBar
.babelrc
{
"presets": ["es2015", "stage-2", "react"],
"plugins": [["import", { "libraryName": "antd-mobile", "style": "css" }],"transform-runtime", "transform-decorators-legacy", "transform-class-properties"],
"comments": false
}
你期待的结果是:
像官网一样正常显示
实际上的结果:
ERROR in ./~/.0.9.8@antd-mobile/lib/button/index.js
Module not found: Error: Can't resolve 'react-native' in 'D:\test\js\1112\react-redux-antd-mobile\node_modules\.0.9.8@antd-mobile\lib\button'
Issue Analytics
- State:
- Created 7 years ago
- Comments:34 (8 by maintainers)
Top Results From Across the Web
next+antd-mobile · Issue #4327 - GitHub
Error: next-transpile-modules - an unexpected error happened when trying to resolve "antd-mobile". Are you sure the name module you are trying ...
Read more >Ant design mobile failed to work in react native - Stack Overflow
I will never make mistake like this one. And the solution is changing ant-mobile to ant-mobile-rn. It works for me.
Read more >FAQ - Ant design pro v2
Ant Design Pro has built-in umi, umi uses webpack devServer to support the proxy. ... If this does not solve your problem, please...
Read more >Customize Theme - Ant Design
We take a typical webpack.config.js file as example to customize it's less-loader options. ... which cause style option of babel-plugin-import not working.
Read more >Customize Theme - Ant Design - A UI Design Language
If you choose other boilerplates, you can write a webpack config about less-loader ... which cause style option of babel-plugin-import not working.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@timzaak https://github.com/ant-design/ant-design-mobile/issues/1010
你的说法不准确,并不是 antd-mobile 来兼容 webpack 2.x, 只是配置方式变了而已,用户选择什么构建工具我们无法控制,你要使用 webpack2,你就得自己探索它的配置方法。
@deot 万分感谢!试了试,真的是按需加载。完美!!
最后总结一下:
具体配置可参照 https://git.oschina.net/timzaak/graphql-web-mobile-starter 项目。不过配置有点复杂,不推荐。
@gooddaddy 你的问题必须看到你完整的配置才可以往下走。