简体   繁体   中英

React - bundle production build using webpack or CRA

So have an idea for a fairly simple app that I want to build using react. I want to be be able to embed this app into any html website therefore my main requirement is that I want to be able to bundle a build into a single 'myappbundle.js' file and embed like so:

<div id="react-app-container-for-host-site></div>
<script="src=https://myhosting/myappbundle.js"></script>

From reading online this is a limitation with create react app as if you want to change the web pack config given out of the box you need to run the eject script, which again by reading online isn't exactly recommended? I'm also not sure if using create-react-app will give me a lot of modules I won't necessarily want or use. As I want to embed my app, the bundle size is quite important to me therefore this could be an issue.

Now I know create-react-app isn't the only way to go about it, and I could create my app using webpack/babel from the off and only install what I need when I need it. The problem here is that I'm fairly new to react development and don't want to throw myself into something I can't maintain ( react / webpack etc where the CLA would handle this for me)... That all said, I'm not against this idea, I'm just curious if this is the only route for my scenario...

Any advice would be much appreciated and just wondering what the best route for me is.

Instead of ejecting the app you can use some lib to override the configuration from create-react-app for your needs like cracojs . It's really powerfull and for what you need it is i guess prevent to split into different chunks.

And if you need something dead simple you have a lot of templates in github, but CRA brings you a lot of future out of the box.

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