How to include React as plain JavaScript file

208 Views Asked by At

Is there a way to achieve this? I use react.js in the front end only and want to keep it like this.

2

There are 2 best solutions below

0
Matthew Barbara On

When you build your application via Yarn/npm, that's what basically you'd be doing. The system will bundle your assets and generates an HTML file. If you open the built index.html you should see your parsed React app in plain JS and HTML.

If you plan to put the build on a CDN, all you need to do is move the assets (JS and CSS) and the index.html wherever you want to host them. Ensure that <script> and <link> are pointing to the bundled assets within your index.html.

<script type="text/javascript" src="/static/js/your-bundle-main.js"></script> <link href="/static/css/your-bundlemain.0a265734.css" rel="stylesheet">

0
Steven Daniel Anderson On

You can use unpkg, is a fast, global content delivery network for everything on npm. Use it to quickly and easily load any file from any package using a URL like:

<script src="unpkg.com/[email protected]/dist/react.min.js"></script>
<script src="unpkg.com/[email protected]/dist/react-dom.min.js"></script>