如何在现有的非React页面中运行React组件?

我正在使用PHP应用程序(它是Joomla,但我认为这不重要 - 我假设 这里的答案是相同的,无论服务器端技术如何)我想在其中的一个页面中嵌入一个React应用程序。</ p>

我在主应用程序树之外构建React应用程序,因为 我只想在我的网络应用程序中输出文件。 我的方法是使用 npm run build </ code>来构建React.js应用程序,然后将 / build </ code>文件夹的输出复制到 / media / my-app中 我网站的</ code>文件夹。</ p>

我的构建过程的输出是一组看起来像 build / static / js / 2.1a11a1a1.chunk.js <的文件。 / code>, build / static / js / runtime-main.d5223cc00.js </ code>, build / static / js / main.0a010202.chunk.js </ code>等等。 这些似乎是由 asset-manifest.json </ code>索引的。</ p>

将这些文件移动到 / media / my-app </ code>做了什么 我需要在我的PHP文件中包含该应用程序才能运行? 我是否需要独立包含React或者它是捆绑包的一部分? 为了能够从清单中运行应用程序,我需要包括什么 - 我假设那些哈希名称不是我们应该直接与之交互的东西?</ p>
</ div>

展开原文

原文

I am working with a PHP app ( it's Joomla, but I don't think that matters much - I assume the answer here would be the same regardless of server-side technology ) and I want to embed a React app into one page of it.

I am building the React app outside my main application tree because I only want the output files in my web app. My approach is to use npm run build to build the React.js app and then copy the output of my /build folder into the /media/my-app folder of my site.

The output of my build process is a set of files that look like build/static/js/2.1a11a1a1.chunk.js, build/static/js/runtime-main.d5223cc00.js, build/static/js/main.0a010202.chunk.js and so on. These appear to be indexed by asset-manifest.json.

Having moved those files into /media/my-app what do I need to include in my PHP file for the app to work? Do I need to include React independently or is it part of the bundle? What do I need to include in order to be able to run the app from the manifest - I assume those hashed names are not something that we are supposed to be interacting with directly?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐