in Education by
I hope I can keep this brief. The basic jist of my issue stems from SASS imports. I have an App Component that handles all the routing. In the imports is a Login Component. In this component is an a .scss import import './Login.scss'; In this file is imports of various other .scss files. Another route in my App component is ForgotPassword component. Similar to Login it has a .scss import of its own. Now, the issue is, if a user loads the Login component, it means that all the css and imports are stored in a css file and that carries over to every other component in my project. Let's say one of the .scss imports was something like Card which styles .Card classes. I have a variable $Card-padding: 15px !default; In ForgetPassword I also have that import. First issue is that I now have two imports of Card and if I try to override the $Card-padding variable it will also override on Login. I am currently using react-loadable in my App component where I handle my routes. import React from "react"; import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; import Loadable from 'react-loadable'; import './App.scss'; const Login = Loadable({ loader: () => import('../../login/Login'), loading() { return null; } }); const ForgotPassword = Loadable({ loader: () => import('../../forgot-password/ForgotPassword'), loading() { return null; } }); const App = () => { return (
} exact /> } exact />
); } export default App; My question really is, can I remove unused CSS with React and Webpack, or is there a better method of css containment so that it cannot be accessed outside of the component? I feel like this is something that lots of people do, but I cannot seem to find out how to do this. There may be a term that I have missed which would lead be to the correct resources. But I am lost. I'm not a huge fan of css in js, a lot of the styling comes from another project that is similar so is much simpler to copy it over other than having to write css in js for each class and permutation. Every question on this on here does not have an accepted answer, so I'm throwing a Hail Mary in the hopes that someone has a React/Webpack solution to this. I had tried ExtractTextPlugin in webpack, but it never seemed to spit out the Login.scss, so I may have configured it incorrectly. I am currently using MiniCssExtractPlugin to compile my scss files. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
if I try to override the $Card-padding variable it will also override on Login. I don't believe you should be selectively overriding sass variables. To override a css property, why not add specific css class for that component: // global styles .card { padding: $Card-padding; } login.scss: $mynewpadding: 100px; .card.login { // override the default padding here padding: $mynewpadding; } forgottenpassword.scss: $myothernewpadding: 30px; .card.forgottenpassword { // overrider the default padding here padding: $myothernewpadding; } imho the above would be much clearer and easier to maintain..

Related questions

0 votes
    I hope I can keep this brief. The basic jist of my issue stems from SASS imports. I have an App ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I want to build my js/css code, write it on disk and serve it using webpack-dev-server in a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    What command is used for remove all stopped containers, unused networks, build caches, and dangling images? docker system kill ... kill -a docker system prune docker system rm -a...
asked Jun 22, 2021 in Technology by JackTerrance
0 votes
    I'm unable to change/remove the link underline and color of the nested text. I checked the debug ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    How to remove bullet points in CSS?...
asked Dec 21, 2020 in Technology by JackTerrance
0 votes
    Knowing that I can version js and css files like Option 1: myJavaScript.js?v=#myVersionNumber# myCSS.css?v= ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What are Bundles in Laravel?...
asked Sep 30, 2021 in Technology by JackTerrance
0 votes
    What is mean by bundles in laravel?...
asked Sep 28, 2021 in Technology by JackTerrance
0 votes
    I couldn't find any good source of knowledge. How complex is to migrate from webpack 2.7 to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Does server-side rendering with react-loadable work with Webpack 4 and Babel 7? I've been unable to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    ______________ are JS functions that you can call from your templates, and encourage you to reuse code and build complex templates a)Expressions b)Helpers c)Template d)Context...
asked Apr 29, 2021 in Technology by JackTerrance
0 votes
    What is the HTML tag under which one can write the JavaScript code? A) B) C)
    Name the two countries formed due to the splitting of Czechoslovakia. Select the correct answer from above options...
asked Aug 3, 2022 in Education by JackTerrance
...