Tôi đã tìm thấy để làm cho hai công việc và sẽ đăng bài ở đây cho bất cứ ai khác tìm kiếm giống nhau. Có lẽ các phương pháp khác để làm điều này, nhưng đây là những gì làm việc cho tôi.
Vì vậy, về cơ bản chúng ta sẽ tạo ra một ứng dụng Cordova sử dụng (nói): cordova tạo testapp com.test.testapp testapp này sẽ cung cấp cho tôi một cấu trúc thư mục như vậy:
testapp
--hooks
--platforms
--plugins
--www
--config.xml
Bây giờ bên trong thư mục testapp chúng tôi chạy: create-react-app teastappReact Điều này sẽ thêm ứng dụng phản ứng của tôi vào trong thư mục testapp. Ứng dụng phản ứng của bạn sẽ có một index.js chính trong thư mục/src.
tôi các index.js hãy chắc chắn để quấn logic chính của bạn bên trong một hàm và sau đó gọi hàm cùng với đối tượng Cordova như vậy:
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)
}
Điều đó sẽ làm gì bây giờ ứng dụng của bạn sẽ có cơ dụ Cordova cùng với các đối tượng Thiết bị như navigator.camera bên trong ứng dụng của bạn.
Cũng trong ứng dụng phản hồi index.html có thể được tìm thấy trong thư mục công cộng sao chép html từ index.html mà bạn sẽ tìm thấy trong thư mục Codova www. Bây giờ chúng ta có thể xóa tất cả các tập tin từ thư mục www. Sau đó chúng tôi sẽ tự tay hoặc thông qua một kịch bản sao chép tất cả các tập tin từ ứng dụng phản ứng xây dựng thư mục để Cordova www thư mục.
Vì vậy, index.html của tôi sẽ trông giống như dưới đây, hãy lưu ý tệp tin cordova.js được bao gồm dưới dạng tập lệnh.
<!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>
Cuối cùng trong bạn phản ứng package.json ứng dụng thêm dòng sau: .... 'trang chủ': "../www" .... này sẽ đảm bảo bạn xây dựng chính thức tệp đang trỏ vào đường dẫn bên phải. chúng tôi cũng có thể thêm các dòng sau trong kịch bản xây dựng package.json của bạn.
"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"
}
Nó có thể là robocopy hoặc cp-r dựa trên hệ điều hành (Windows/Linux, v.v ..).
Chúng tôi sẽ có ứng dụng Cordova của chúng tôi sẵn sàng để xây dựng với cordova xây dựng android/ios.
Tôi đã tìm ra cách để làm cho cả hai hoạt động và sẽ Đăng ở đây cho bất kỳ ai khác đang tìm kiếm cùng một câu trả lời. Nó là khá tầm thường và có thể có các phương pháp khác, nhưng đây là những gì wprked cho tôi khá tốt. –