-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Easily create react-native-web apps with create-react-app #1192
Comments
Thanks for looking to fill in some of the gaps. Have you thought about sharing this with the create-react-app project too? |
I'll submit an issue and see if there is interest in upstreaming the change. |
Another option is to use
babelIncludeOverwites the // config-overide.js
module.exports = override(
babelInclude([
path.resolve('src'), // make sure you link your own source
path.resolve('node_modules/native-base-shoutem-theme'),
path.resolve('node_modules/react-navigation'),
path.resolve('node_modules/react-native-easy-grid')
])
); |
Thank you for suggesting this @dalcib! The override config looks clean and simple. I was aware of react-app-rewired, but thought it was no longer supported and was waiting for its to successor to emerge. In the meantime, it was easy enough to create a simple fork. I can see how the naive pattern match will break with variously named react native packages so explicit will be more robust. Do you know if react-app-rewired will continue to be maintained as dependency of customize-cra or if it will be merged in? |
@amsb, see the comment bellow from timarney/react-app-rewired#162 (comment)
|
Piggy backing off of @dalcib, here is an example of a full implementation of the CRA config required for RNW: // config-overrides.js
const {
addWebpackAlias,
babelInclude,
fixBabelImports,
override,
} = require('customize-cra')
const path = require('path')
module.exports = override(
fixBabelImports('module-resolver', {
alias: {
'^react-native$': 'react-native-web',
},
}),
addWebpackAlias({
'react-native': 'react-native-web',
'react-native-svg': 'svgs', // not necessary unless you wanted to do this
}),
babelInclude([
path.resolve('src'), // make sure you link your own source
// any react-native modules you need babel to compile
path.resolve('node_modules/react-native-indicators'),
path.resolve('node_modules/react-native-popup-menu'),
path.resolve('node_modules/react-native-vector-icons'),
path.resolve('node_modules/react-native-web-linear-gradient'),
path.resolve('node_modules/react-router-native'),
]),
) And then update your npm scripts to be |
@pcooney10 Really helpful! |
Thanks a lot, I will try this asap. ! |
I have made an easy tool to generate your React Native Web app with fast refresh on all platforms https://github.com/web-ridge/create-react-native-web-application
It used latest create react app and latest react native Cli in background and merges both |
@pcooney10 thanks btw I used your config! |
Here is the end result of a created app with some simple examples to show the power of React Native Web |
In experimenting with react-native-web we found that while create-react-app will helpfully alias react-native-web, many react-native packages are not distributed in compiled form. For example, react-native-paper appears to work fairly well with react-native-web but can't be easily added to a create-react-app project. To fix this issue and allow continued experimentation, we forked create-react-app 2.1.1 and extended the webpack config to compile
react-native-*
packages innode_modules
with the full suite of transforms, including JSX and stripping flow types. You can now easily get started consuming other react-native projects within a create-react-app by bootstrapping your app with the command (assuming you use npm 5.2+):This isn't well tested yet as we're primarily experimenting with react-native-paper, but we thought it might be useful to a broader audience. More information here:
The text was updated successfully, but these errors were encountered: