Search code examples
javascriptreact-nativeantdcreate-react-native-app

Does ant-design-mobile work with create-react-native-app?


I need to add {"plugins": [["import", { "libraryName": "antd-mobile" }]]} to .babelrc from a project generated by create-react-native-app to make ant-design-mobile work in react native.

I have started a new project with create-react-native-app. Change the .babelrc to this:

 {
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source",
      ]
    }
  },
  "plugins": [
    ["import", { "libraryName": "antd-mobile" }]
  ]
}

Class:

import { Button } from 'antd-mobile';

export class Screen extends React.Component<any,{}>{
   render(){
     return(
            <View>
                <Button>Something</Button>
            </View>
        )
   }
}

However, I'm still getting this error on start:

Note: must use https://github.com/ant-design/babel-plugin-import .
For more information, please see https://github.com/ant-design/ant-design-mobile/issues/602

Can anyone point me to a solution?


Solution

  • You can take a look at official react-native app demo: https://github.com/ant-design/antd-mobile-samples/tree/master/react-native