question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Is there any way to only extract the css files from initial chunk?

See original GitHub issue

I don’t think the browser needs to make extra an request to fetch the css file of its own async js chunk which it has been loaded. So I want to disable. It should be something like the “fallback” option of extract-text-webpack-plugin and its behavior. However, I’m not able to find an equivalent way with mini-css-extract-plugin and webpack 4.

For example, let’s say we have several pages will be loaded on demand:

// routes.js inside intial-chunk.js
import './initial-chunk.css';
const routes: [
  {
    module: () => import('pageA')
  }
];

// pageA.js
import './pageA.css';
export default {
  // something that pageA should do
};

// pageB.js
import './pageB.css';
export default {
  // something that pageB should do
};

And the output files should be like this:

vendor.js
initial-chunk.js
initial-chunk.css
pageA.js
pageB.js
// Note that there isn't a "pageA.css" or "pageB.css" file. These css files are inside their own chunks and loaded by some other loaders, `style-loader` for example

How can I achieve this? Thank you very much.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jcreamer898commented, Apr 24, 2019

Was there a resolution on this? We have a bunch of dynamic imports, and they’re each getting their own CSS files and I’d like to bubble them up to their closest entrypoint, but haven’t been able to find the right config to achieve it.

0reactions
lsycxyjcommented, Aug 30, 2019

No, I want to load css modules only when you need

Read more comments on GitHub >

github_iconTop Results From Across the Web

extracting one css file per webpack chunk (require.ensure)
By passing {allChunks: true} it extracts all the css in all the chunks and puts in one css file. But it doesn't solve...
Read more >
Separating CSS - SurviveJS
Webpack provides a means to generate a separate CSS bundles using mini-css-extract-plugin (MCEP). It can aggregate multiple CSS files into one.
Read more >
extract-css-chunks-webpack-plugin - npm
Extract CSS from chunks into stylesheets + HMR. Supports Webpack 4 + SSR. Latest version: 4.9.0, last published: 2 years ago.
Read more >
How Do You Remove Unused CSS From a Site?
To clean CSS with multiple pages just use that tool for all pages with different layouts. Then merge all exported CSS files to...
Read more >
9 tricks to eliminate render blocking resources - LogRocket Blog
The @import rule lets you import CSS from other stylesheets, but this causes the browser to process your CSS file more slowly because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found