score:2
yes, this can be done. you'll need commonschunkplugin
in addition to extracttextplugin
. also, define multiple entry points
entry: {
a: "./a",
b: "./b",
c: "./c",
},
and configure extracttextplugin
to use entry point names as css file names
new extracttextplugin({
filename: "[name].css"
}),
see a full example here:
score:2
while i may not answer your question how to split css files so that only the necessary ones are loaded the way you want the question to be answered (no plugin or that sort of thing), i hope to give you a possible alternative.
styled-components
use the new es6 feature tagged template literal to style the components inside the javascript file. i think using this library would solve your problem of loading only the necessary css files, because there would be no more css files per se.
react-boilerplate
chose styled-components
over sass, because
styled-components
have a more powerful approach: instead of trying to give a styling language programmatic abilities, it pulls logic and configuration out into js these features belong.
so using styled-components
would not only solve your problem of loading only the necessary css, but it would further add to the decoupling of your application, makes it easier to test the design and reason about your app.
here's the live demo where you can experiment with the styled-components
and check how it works.
Source: stackoverflow.com
Related Query
- CSS Code Splitting with Webpack 2 and React Router
- set chunk path a with webpack and react lazy code splitting
- Trying to implement a React "Lazy" route for code splitting with React Route and Webpack
- How to import CSS modules with Typescript, React and Webpack
- Remove unused css with React and Webpack
- Using React Router with CDN and without webpack or browserify
- the pros and const of react ssr with code splitting and now React.Lazy
- Webpack 2 + React - nested routes when code splitting with System.import
- React Router v5 accompanied with Code Splitting, and Data Prefetching with the use of Server Side Rendering
- React code splitting and server side rendering with System.import or require.ensure
- How to determine the order of css in my create react app build with webpack and customize-cra?
- React router v4 broswer history not working with code splitting
- React router 4 - routing + code splitting, with webpack 1.9
- Dynamically load javascript chunk with webpack and react router
- React check if css has loaded with Webpack and React
- React router with basename and webpack initial url
- react scroll to a component without react router and with most basic code
- React router - code splitting lazy imports. Switch with Suspense outside
- React router is not working with webpack server and redux?
- Configuring CSS modules in development/production with webpack and React
- Code splitting with React Loadable and routes with containers
- I am using react js and jsx and css using webpack and my code fails to compile when I add an image to the css
- How to use code splitting with webpack in react app with components exported as export * from '...'
- Themes in Tailwind CSS are not working with Webpack and React
- Typescript + react 17 + webpack 5. Code splitting with react HashRouter not working
- React Redux Server Side Rendering with code splitting and injecting
- Add Favicon with React and Webpack
- SyntaxError with Jest and React and importing CSS files
- How to set up Babel 6 stage 0 with React and Webpack
- Formatting code with <pre> tag in React and JSX
More Query from same tag
- API Platform / React - uploading file not working
- Djanog with React how to reset user password by sending user an email
- How to introduce your own style when using Snipcart?
- Replacing custom html tags in react
- Programmatically navigating using react-router
- componentDidUpdate doesn't update state with Redux
- How to wrap words with anchor tags in react if string contains certain symbols
- Redux reducer failing to remove array element
- Why useState is not accepting input received from the GET request?
- React-redux `useSelector` complains about Invalid Hook call
- Why is day off by 1 and hours is way off on mor ISO 8601 in Moment js?
- webpack config with optional usage of BundleAnalyzerPlugin
- How to store generated api keys in React?
- React Material UI - Center Box vertically
- Fetch API in React for JSON file: Uncaught (in promise) SyntaxError: Unexpected token � in JSON at position 0
- React Native Error Cannot find module 'metro-config/src/defaults/blacklist'
- TypeError: Cannot read property 'username' of undefined React.js
- How can I add as many buttons as passed in prop number with out causing too many re-render on React?
- Bootstrap's accordeon shows all items opened initially in React app, should be closed
- SyntaxError: Unexpected identifier while deploying React application on Docker container
- react refresh defaultValue
- Should a container component *always* connect to Redux?
- React Router - how to constrain params in route matching?
- Distinguish row clicks in Antd (ant design) table React component
- How to iterate through array inside objects which is inside main object
- Material-ui & TouchTap: Getting key of ListItem
- warning: it is defined but never used
- ReactJS - React.Children.forEach - Can I get the child component name?
- React js useState array does not update
- Add a span inside a div with dangerouslySetInnerHTML for showing a tooltip