简体   繁体   English

使用npm将React代码渲染为HTML文件

[英]Render React code to HTML file with npm

I didn't know how to name this question but here is the thing. 我不知道如何命名这个问题,但这就是问题。 I installed React with NPM: npx create-react-app my-app and I start app with npm start . 我安装了带有NPM的React: npx create-react-app my-app并使用npm start启动应用npm start After that localhost:3000 opens. 之后,localhost:3000打开。 The thing is html file in folder public isn't connected anyhow to the script. 问题是文件夹public html文件始终未连接到脚本。

I want to serve the development with package called "serve". 我想使用称为“ serve”的程序包为开发服务。 The only thing there is nothing to serve, the HTML file in public isn't updated at all while I can't serve App.js or anything like that. 唯一没有什么可提供的,公共的HTML文件根本无法更新,而我无法提供App.js或类似的东西。

Is it required to use CDN links for this task? 是否需要使用CDN链接来完成此任务? Or how else it is possible to connect React to that generated html file? 或者还有什么可能将React连接到生成的html文件?

You need to setup your environment with Webpack. 您需要使用Webpack设置环境。 you can follow this tutorial: https://www.valentinog.com/blog/react-webpack-babel/ 您可以按照以下教程进行操作: https : //www.valentinog.com/blog/react-webpack-babel/

Or you can clone a react boilerplate project from github directly. 或者,您可以直接从github克隆react样板项目。

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

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