简体   繁体   English

Phonegap 和 React 应用程序的 Webpack 配置?

[英]Webpack configuration for Phonegap and React app?

I am building this android/iOS app using Phonegap, which will be build on React (not React Native).我正在使用 Phonegap 构建这个 android/iOS 应用程序,它将构建在 React(而不是 React Native)上。 I configured the webpack based on my needs and when I run npm run build, the android app viewer in the Phone renders the app correctly .我根据自己的需要配置了 webpack,当我运行 npm run build 时,手机中的 android 应用程序查看器会正确呈现应用程序 But the problem is, if I change any file in the www folder given by webpack, the Phonegap server picks up the changes but in the android viewer does not re-render the view .但问题是,如果我更改 webpack 提供的 www 文件夹中的任何文件,Phonegap 服务器会获取更改但在 android 查看器中不会重新渲染视图

Any idea how can I streamline the whole process with webpack so that the webpack served content can be picked up by Phonegap phone app or webpack will spit out the files in the www folder on the fly and Phonegap server will pick it up and render the view in it's own server or in the Phonegap android app?任何想法如何使用 webpack 简化整个过程,以便可以通过 Phonegap 手机应用程序获取 webpack 提供的内容,或者 webpack 将动态吐出 www 文件夹中的文件,Phonegap 服务器将获取它并呈现视图在它自己的服务器中还是在 Phonegap android 应用程序中?

Here is my folder structure-这是我的文件夹结构-

文件夹结构

Phonegap is serving files from www to my android phone. Phonegap 正在将文件从 www 提供给我的 android 手机。 But when I change any file there manually, Phonegap picks up the changes but the page is not re-rendered on the phone.但是当我手动更改任何文件时,Phonegap 会获取更改但页面不会在手机上重新呈现。

At the same time, how can I configure webpack to make changes to the build folder 'www' on the fly when I save a file from src with new change?同时,当我使用新的更改从 src 保存文件时,如何配置 webpack 以动态更改构建文件夹“www”? So that Phonegap picks up the changes and rerenderes?那么 Phonegap 会接收更改并重新渲染吗?

In the webpack config file, set the output destination to your www folder.在 webpack 配置文件中,将输出目标设置为您的www文件夹。 Here's a sample of how I got it working:这是我如何让它工作的示例:

entry: './src/index',
output: {
  path: path.resolve(__dirname, 'www'),
  filename: '[name].bundle.js',
  hotUpdateChunkFilename: 'hot/hot-update.js',
  hotUpdateMainFilename: 'hot/hot-update.json',
},

So your bundled .js file will get inserted inside www/ or www/js/ or wherever you need and phonegap serve will pick up the changes.因此,您捆绑的.js文件将插入www/www/js/或您需要的任何位置,并且phonegap serve将接收更改。

I also used webpack-dev-server and write-file-webpack-plugin so the former will actually write to the main.bundle.js file but I had some issues where the hot replacing was happening too slowly, phonegap was picking up hot files which were temporarily inserted and then removed, and phonegap serve was crashing because eventually those temp files were not found.我还使用了webpack-dev-serverwrite-file-webpack-plugin所以前者实际上会写入main.bundle.js文件,但我遇到了一些问题,即热替换发生得太慢,phonegap 正在获取热文件临时插入然后删除,并且 phonegap 服务崩溃,因为最终找不到这些临时文件。 Trying webpack -w now.现在尝试webpack -w

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

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