简体   繁体   English

如何在C面板上构建React JS静态

[英]How to build react js static on c panel

I have built my react js app with create-react-app configs and it works fine in development build of React. 我已经使用create-react-app配置构建了我的react js应用,并且在React的开发版本中运行良好。 I built that with npm build command and now i have build folder. 我用npm build命令构建了它,现在有了build文件夹。 this web page is static (server-less), Now I want to know how to use that and where put files in Cpanel. 该网页是静态的(无服务器),现在我想知道如何使用它以及将文件放在Cpanel中的位置。

After the bundle realized by webpack , you can check the transpiled and minified version inside the build folder. 通过webpack实现捆绑包后,您可以检查build文件夹中已翻译和缩小的版本。 You should upload all the content to your public_html or another folder. 您应该将所有内容上载到public_html或另一个文件夹。

And the meaning of server-less is totally different than you're using. 无服务器的含义与您所使用的完全不同。 Check this article to understand what it is: What is serverless . 查看本文以了解它是什么什么是无服务器

I do not use CRA boilerplate since i have my own but in your case, you should find where your js bundle is. 我不使用CRA样板,因为我有自己的样板,但是在您的情况下,您应该找到js包所在的位置。 You can find the bundle location in the webpack config. 您可以在webpack配置中找到包的位置。 Then append that to your html somehow like this: 然后像这样将其附加到您的html中:

<div id="root"></div>
<script src='your-js-bundle'></script>

Assuming that somewhere in your code, you are appending your js code into a div like this: 假设在代码中的某处,您将js代码附加到div中,如下所示:

const element = <h1>Hello, world</h1>; // assuming element is your entry point
ReactDOM.render(element, document.getElementById('root'));

That works if its just simple react project your working on (No SSR and such) 如果它只是您的工作而已,那么它就很有效(没有SSR等)

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

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