简体   繁体   中英

How to convert a react-native-like js file to plain javascript file?

I want to convert a react-native-like js file to plain javascript file so that it can be execute by JavaScriptCore. I know browserify can convert Node-like file to plain javascript file. But when I execute :

browserify script.js -o bundle.js -t [ babelify --presets [ es2015 react ] ]

it returns an error:

Cannot find module 'ActivityIndicator' from '/home/yjy/Work/react_native/Webview/node_modules/react-native/Libraries/react-native'

The script.js like follows:

import React, { Component } from 'react';
import {
  AppRegistry,
  Text,
} from 'react-native';

class Hello extends Component {
  render() {
    return (
      <Text>HelloWorld.....</Text>
    );
  }
}

I have tried to copy the ActivityIndicator.js file to this folder,but it still report the same error.How can I solve this problem? What's more,how does react native solve bundle these modules to a bundle file? What's the difference between index.android.bundle file and the executable plain js file?

Any suggestion is appreciated!

You could hit the packager url with curl to get the bundle. The bundle is just 'browserifed' code that can run in JSCore. It probably won't be very readable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM