简体   繁体   English

如何将类似react-native的js文件转换为纯javascript文件?

[英]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. 我想将类似react-native的js文件转换为普通的javascript文件,以便可以由JavaScriptCore执行。 I know browserify can convert Node-like file to plain javascript file. 我知道browserify可以将类似Node的文件转换为纯javascript文件。 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: 如下所示的script.js:

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? 我试图将ActivityIndi​​cator.js文件复制到此文件夹,但仍报告相同的错误。如何解决此问题? 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? index.android.bundle文件和可执行的纯js文件有什么区别?

Any suggestion is appreciated! 任何建议表示赞赏!

You could hit the packager url with curl to get the bundle. 您可以使用curl来访问打包程序的URL以获取捆绑包。 The bundle is just 'browserifed' code that can run in JSCore. 该捆绑包只是可以在JSCore中运行的“浏览简化”代码。 It probably won't be very readable. 它可能不太可读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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