How to load css & js from public folder reactjs create-react-app - reactjs

i created create-react-app and i placed index.html and css in public folder and imported css and js using link and script tags but not working completely, could any one please help me on this.

Related

Have a static html page in next.js project (outside of /public/-folder)

I have created a new next.js project. Is it possible to have an accessible static html page "outside" the project?
For example the structure would look like this:
.next
components
node_modules
pages
public
styles
aboutus
Now looking at the folder /aboutus/, it will have a structure like this:
css (folder)
js (folder)
images (folder)
index.html
Where the index.html references the css, js and the images.
But when i call http://localhost:3000/aboutus it gives me a 404 error.
Already tried this setup locally, but didn't work.
It turned out a 404 error.
I expect that to work.
Is it possible to have an accessible static html page "outside" the project?
No. Only files that are in the pages folder are generated as pages. pages in NextJS
The closest you can get to accomplish that is by running npm run export and manually insert your "aboutus" folder in the "out" folder. But the project wont have the benefits of These features.
In case the .js is not Next related, have you tried to put the aboutus folder in public/aboutus ?

How to Integrate third party libraries into React JS

I had a template, that I wanted to convert to React JS components, and I successfully did that. As all of us know, that there are bunch of libraries used in a template. What I first did is, I inserted the .css and .js libraries into the react app through the index.html file, in the public folder of the create-react-app boiler plate. It successfully used the styles and scripts from the inserted .js and .css files. But the problem occurred when I added routing to the react app.
When, I navigate to another route through a link, the component loads, but the required styles and scripts doesn't loads. I don't know what the problem is. I tried to import the scripts and styles to the parent component which is home.js. The styles worked properly, but the libraries used in template are :
bootstrap.min.js,
eva.min.js,
feather.min.js,
jquery.min.js,
jquery-slim.min.js, and
popper.min.js.
On each import of the above libraries, it shows different errors. But as an example, for jquery.min.js it shows the following error :
In public folder add the following code in of the index.html page.
<base href="/">

I want to integrate Bootstrap to my react project (can we add them through dependency)

I have a custom files like
- bootstrap.css
- bootstrap.js
- owl-carosel.min.css
- owl-carosel.min.js
etc. I want to add them locally from my assets folder inside src to my index.js
I have tried adding them to my index.html but the problem is i have to move my assets folder to public folder.
When i try adding them using import statement it Fails to compile
Error:
Failed to compile
./src/assets/css/font-awesome.min.css (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-3-1!./node_modules/postcss-loader/src??postcss!./src/assets/css/font-awesome.min.css)
Module not found: Can't resolve '../fonts/fontawesome-webfont.eot' in '/home/cedex12/Gokul/food-day/src/assets/css'
Can we add them like
Step1:'bootstrap': 'file:/path/to/your/repo'
Step2:npm install
I want to integrate them to my index.js file.
With js you can use the function import() that allow you to import external js file in a js file ;) Just read the doc
try using react-bootstrap framework its build with react components! here a link:https://react-bootstrap.github.io/

ReactNative Webview

React js : I am trying to open my react js production build folder under which the one html file is placed after run npm run build.
React Native: I am using react-native-webview Plugin for open the same index.html file. For android I placed this folder under assets.
The codebase giving me error File_Not_Found.
The build html file is minify html file. When I try to use any url here or any development plain html it is working fine. For this minify file it is not working.
Please help.
I am using this code for android react native.
if(isAndroid){
console.log(isAndroid);
return (
)
}
I want to open production this react js build folder html file in react native webview.
Create an object
const index = require('./assets/index.html');
set your source to the object instead of using a uri.

Using Custom Script from a Purchased Theme in React

I'm refactoring HTML into React. The HTML uses a purchased theme that relies on a few custom JS files including jQuery. How do I link custom scripts to components in React? Do I link them in my index.html file in the public folder? Or do I need to link them in each component file?
You can link them in the index.html or you can import them in your JavaScript. I tend to import in my root JavaScript file so that the imported files are bundled with the rest of my JavaScript (if using a bundler like webpack). For example, to include the JavaScript required for materialize I simply add
require("./js/bin/materialize");
in my app.jsx file.

Resources