mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-28 12:24:51 +08:00
41 lines
908 B
Markdown
41 lines
908 B
Markdown
# React Native
|
|
|
|
This is an experimental feature to support: using community-developed React
|
|
Native components on the Web; and rendering React Native apps to Web.
|
|
|
|
Use a module loader that supports package aliases (e.g., webpack), and alias
|
|
`react-native` to `react-native-web`.
|
|
|
|
```js
|
|
// webpack.config.js
|
|
|
|
module.exports = {
|
|
resolve: {
|
|
alias: {
|
|
'react-native': 'react-native-web'
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
Web-specific implementations can use the `*.web.js` naming pattern, which
|
|
webpack will resolve.
|
|
|
|
Minor platform differences can use the `Platform` module.
|
|
|
|
```js
|
|
import { AppRegistry, Platform, StyleSheet } from 'react-native'
|
|
|
|
const styles = StyleSheet.create({
|
|
height: (Platform.OS === 'web') ? 200 : 100
|
|
})
|
|
|
|
AppRegistry.registerComponent('MyApp', () => MyApp)
|
|
|
|
if (Platform.OS === 'web') {
|
|
AppRegistry.runApplication('MyApp', {
|
|
rootTag: document.getElementById('react-root')
|
|
});
|
|
}
|
|
```
|