I'm using Create React App and I would like to use a JS library that isn't available via npm. How would I go about integrating that into my app? I think I can simply add a script tag for it in public/index.html for development purposes but I'm guessing that won't include it in the final build code. Any suggestions would be welcome.
You can add your script to the public folder and include it in the public/index.html file.
<script type="text/javascript" src="%PUBLIC_URL%/my-script.js"></script>
Related
I have copied js (handy.min.js) in my project's public directory
I included it in my index.html using %PUBLIC_URL%/handy.min.js
But this file not found when I run my application.
I created project using create-react-app.
No webpack specific config
Any suggestion how to make this file available after I run react build profile.pro
You should add this to your index.html file:
<script src="%PUBLIC_URL%/handy.min.js" ></script>
further reading: https://www.geeksforgeeks.org/how-to-use-files-in-public-folder-in-reactjs/
I have build a react app with some external libraries and would like to include it into an existing project that has nothing put JSP's.
Running the command react-scripts build generates files in a build folder.
build/asset-manifest.json
build/favicon.ico
build/index.html
build/manifest.json
build/precache-manifest.23802519359aee1ffa0ec2f3ba332c80.js
build/work.js
build/static
build/tab.png
What do I include and how do I include these files.
I have tried to add the index.html into index.jsp but is doesnt seem to work. Although I do see the title change to what is in my react app.
<%#include file="index.html"%>
or do I need to include all the files similar to how I added index.html
The index.html file does load a couple of script files in the build/js folder like so below.
<script src="/static/js/2.57fa75d6.chunk.js"></script><script src="/static/js/main.fe75a1b9.chunk.js"></script>
I have project with similar requirements as yours.
Some info needs to be render at server, but could not find proper way to do it in java, so I created maven plugin for that:
https://github.com/maasdi/react-assets-maven-plugin
You can try check it out, hope that can help with yours.
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)
I'm using ghcjs-0.2.0.9006030_ghc-7.10.3 with stack lts-6.30 to build a frontend app. Inspired by this post, I decided to use react-flux and material-ui. I added React's CDN link to my index.html, and configured GHCJSi to use a custom index-dev.html when working with the repl.(React's CDN link is also included in index-dev.html)
However, with material-ui-next, the official installation method is to use NPM. They provide no CDN link. So how to use this library in a GHCJS project? I think one of the following should work:
Use the CDN link provided by jsDelivr. (Though this link doesn't work)
Find some way to bundle material-ui-next and put it in js-sources field in cabal, so that it can be linked with our app at build time.
Any help is appreciated.
In the package.json of material-ui, scripts build:umd:prod and build:umd:dev can be used to build UMD bundles of the package. So you can use the CDN link provided by unpkg.
Even though material-ui doesn't declare a peer dependency on react-transition-group, it expects react-transition-group/TransitionGroup to be present. So we have to add the following code before the link to material-ui
<script crossorigin="anonymous" src="https://unpkg.com/react-transition-group#2.2.1/dist/react-transition-group.js"></script>
<script>
window["react-transition-group/TransitionGroup"] = ReactTransitionGroup.TransitionGroup;
</script>
I created a issue on material-ui's github repository, see that issue for more details.
Is there a way to achieve this? I use react.js in the front end only and want to keep it like this.
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">
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/react#15.3.1/dist/react.min.js"></script>
<script src="unpkg.com/react-dom#15.3.1/dist/react-dom.min.js"></script>