我发现使这两个工作,并张贴在这里为别人寻找相同。也许有其他方法可以做到这一点,但这对我来说很有用。
所以基本上,我们将使用创建应用程序科尔多瓦(说): 科尔多瓦创建testapp com.test.testapp testapp 这会给我一个文件夹结构像这样:
testapp
--hooks
--platforms
--plugins
--www
--config.xml
现在testapp文件夹中我们运行:创建反应的应用程序内teastappReact 这将增加我的反应testapp文件夹内的应用程序。 你反应的应用程序将有一个主index.js在/ src目录。
我的index.js一定要包装你的主逻辑函数中,然后调用函数与科尔多瓦对象一起,像这样:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
const startApp =() => {
ReactDOM.render(
<App />,
document.getElementById('root')
);
}
if(!window.cordova) {
startApp()
} else {
document.addEventListener('deviceready', startApp, false)
}
这应该做,现在你的应用程序将沿着有科尔多瓦实例在你的应用中使用像navigator.camera这样的Device对象。
而且在你的反应可以在公共文件夹中找到的,你将在Codova WWW文件夹中找到的index.html复制HTML应用程序的index.html。现在我们可以从www文件夹中删除所有文件。我们稍后将手动或通过脚本将反应应用程序生成文件夹中的所有文件复制到Cordova www文件夹。
所以我的index.html看起来像下面,注意cordova.js文件多数民众赞成列入为脚本。
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src * data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!-- Latest compiled and minified CSS -->
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>
最后,在你的应用程序的反应的package.json添加以下行: .... ‘主页’:“../www” .... 这将确保您的最终版本文件指向正确的路径。 我们也可以在您的package.json构建脚本添加以下代码行。
"scripts": {
"start": "react-scripts start",
***"build": "react-scripts build && robocopy .\\build ..\\www /MIR",***
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"deploy": "npm run build&&gh-pages -d build"
}
它可以是基于OS(Windows/Linux等)的robocopy或cp-r。
我们应该有科尔多瓦的应用程序准备与 科尔多瓦构建Android/IOS来构建。
我已想出如何使这两个工作,并张贴在这里为别人寻找相同的答案。这是非常微不足道的,可能还有其他方法,但这对我来说是非常好的。 –