The app has two sides, Blog and management.
I code the management part with ant design.
The blog part is with html template. (assets file folder in css, js, img exc.)
While rendering React, all css and js files print on the same page and confusion occurs. Css files are corrupted in design because they overlap.
I use craco as the web configuration, you can find the configuration in the link below.
https://ant.design/docs/react/use-in-typescript
Is there a way to separate two templates with react router dom? For example, can different theme files work on each page?
Related
I know react is for Single Page Application. I have already build a complete application. I have a particular 3rd party integration that requires javascript and css files. I cannot add those external scripts as it breaks my entire application by overriding css and js.
I need to have a separate admin.html file which can have its own css and javascript tags. I do not want any conflict with my react app which renders on index.html
I tried to eject create-react-app and add a new admin.html.
https://github.com/facebook/create-react-app/issues/1084#issuecomment-568550609
But it uses only one page(index.html). This will not help me because I need completely a separate html file which I can import any javascript or css freely without any conflict on my index.html
Currently the possibility I thought was to create a separate react application just to render to this admin.html. So that there won't be any conflicts between javascript and css. But I want to know if there is an alternate way that I can achieve it in create-react-app. If so, simple example would be greatly appreciated.
PS: I need to redirect from one of components in my application to this new view admin.html with some data
I got a bootstrap theme that consists of HTML, CSS and Javascript. Now, I want to implement it (or let's say make it functional) in Vue. I have my index.html file that contains the container and it works. Now, my theme does have an index.html file as well. I just thought I can copy the whole file into the Vue-index.html and add the div with the id "app" around the area that changes the content. But it does not work. Basically, Vue does not load any external css or js files even though I reference them correctly (with relative reference using the dot: ./assets/css/style.css). It works inside a .vue-file (i.e. component) but not inside the index.html. What do I do wrong?
Yep, beginner here.
When you put them inside your index.html they are not compiled.
You can read about it HERE
Your index.html is something called a target. Vue uses this file as a mounting point for the rest of the application, so it's kept relatively clean, most likely with just metadata and a DOM mounting point. It works by loading the index.html in the browser and then mounting your Vue application on top of it.
If you're trying to apply some styles to a Vue application/components, your best bet is to modify *.vue files inside the app source of your Vue project (typically, /your-project/src). They will contain snippets of relevant sections/components alongside their logic (JavaScript) and styles (CSS/Sass), provided your project uses Single-File Components format.
For future reference:
It's hard to offer a solution without knowing the structure of your project, what type of components you are using, or even having code samples to get an idea of how things are working inside.
We'd need more information to be able to help you more accurately, so maybe you could create a lightweight demo on an interactive platform like codesandbox.io?
I'm currently developing a website/webapp (I don't really know the clear distinction between it) for my school project. Initially I was planning to develop entirely through just HTML/CSS and JS, however, my adviser told me to use react framework for parts of the pages instead of just doing it with Java for the sake of simplicity. This has been really messing me up since I have no background in web development and I'm confused in general.
I currently have all of the HTML pages styled with CSS, and I was able to transition part of the web-app to react using create-react-app. However, I have no clue how to connect these two.
I created the my-app folder inside the main directory which contains most of the HTML folders, but how would I go by to
1. Access the react app from the HTML page?
2. Access the HTML page in the main directory from the react app?
Following is my directory as a reference
mainDir
|_____bunch of html files
|_____css //contains all css files
|_____img // contains all images
|_____my-app
|____all the files created by create-react-app
Approaches I have tried:
- using the in the HTML pages in the main directory to jump to index.html in the my-app file to load the app
- changing the file path on the tag inside the App.js render() function of each class to something like ../../welcome.html which is the relative path to an HTML in the main directory.
Thank you for your help in advance. I'm welcome to any and all suggestions! If there isn't enough information to assess the situation, please let me know!
Checkout
This Example source code, from React.js: "Add React in One Minute" guide.
What is it?
It's a super bare-minimum implementation of React using:
1 x .html file
1 x .js file
Given your current setup, I'd say it's a lot simpler than trying to incorporate create-react-app.
Let me know if this helps; I'm happy to delete this if it's not useful.
From what I understand extract-text-webpack-plugin bundles all css files imported in your React components into a single separate CSS file. The separate CSS file can then be referenced in your HTML header to prevent FOUC (Flash Of Unstyled Content). Using extract-text-webpack-plugin counteracts some of the benefits of importing your CSS in your React component js files such as hot-loading.
What is then the difference between using extract-text-webpack-plugin and replacing all stylesheet imports in your component files with a single link to a merged CSS file in your HTML template header?
Does it matter whether you use CSS modules or import your CSS?
UPDATE: Added example for clarification.
Scenario A:
component1.css (imported in component1.js)
component2.css (imported in component2.js)
bundled CSS file generated by extract-text-webpack-plugin (called in the HTML header)
Scenario B:
component1.css (not referenced in js files)
component2.css (not referenced in js files)
master CSS file merged using SASS, Laravel mix.style method etc. (called in the HTML header)
Why go with Scenario A and not B?
Good question ariebear!
If you want to use css modules, then yes, there's definitely a benefit to importing the css files into your js files/react components. The main one is that you no longer have to concern yourself with scoping issues, or worry about writing the same class in 2 different areas. The cascade becomes localized to each component.
If you're not using css modules, then there isn't much benefit at all. Sure, you get hot reloading, but there are other solutions available for that.
Hope that helps!
The advantages to combining all your stylesheets into one is that the browser makes a separate request for each stylesheet. If you combine several into one, you will only make one request.
Using this plugin, your styles will no longer be inlined into your JS bundle, which can improve performance as the CSS bundle will be loaded in parallel to the JS bundle.
You're asking a lot of different questions here, so here's my best shot.
You'd use extract-text-plugin in production. Hot reloading isn't necessary in production and you're right that it gets rid of FOUC. There are a few other advantages listed straight from the source as well.
You can still import your .css into your components, if you wish to- or keep them separate. It does matter if you import or require your CSS, that has to do with if you're using es2015 or not.
I am pretty new to reactjs. Right now my reactjs app is pretty big with many pages and five different CSS files for each big component I am using react-helmet to use CSS for different component.
Do I have to compress css into one file or my method is correct?
I am also rendering both client and server-side with reactjs.
You should start using webpack + react + css. This is a far better way than using helmet to added different styles based on the page.
Hope this helps!