简体   繁体   中英

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. I built that with npm build command and now i have build folder. this web page is static (server-less), Now I want to know how to use that and where put files in Cpanel.

After the bundle realized by webpack , you can check the transpiled and minified version inside the build folder. You should upload all the content to your public_html or another folder.

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. You can find the bundle location in the webpack config. Then append that to your html somehow like this:

<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:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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