Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lsycxyj opened this issue Mar 28, 2019 · 7 comments
Closed

Comments

@lsycxyj
Copy link

lsycxyj commented Mar 28, 2019

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.

@alexander-akait
Copy link
Member

Please use gitter or stackoverflow for questions, it is bug tracker, thanks!

You style-loader/url or style-loader/usage.

@jcreamer898
Copy link

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.

@lsycxyj
Copy link
Author

lsycxyj commented Jul 21, 2019

@jcreamer898 I've never found the right config to solve this problem with style-loader. So I tried to create a pull request #432 to solve it.

@yanguoyu
Copy link

yanguoyu commented Aug 29, 2019

image

maybe you can use this, it work for me. only create two css. not 1.css, 2.css, 3.css....

@lsycxyj
Copy link
Author

lsycxyj commented Aug 29, 2019

In this way, you will have to load a lot of other css rules when you don't need.

image

maybe you can use this, it work for me. only create two css. not 1.css, 2.css, 3.css....

@yanguoyu
Copy link

is this not your want?

@lsycxyj
Copy link
Author

lsycxyj commented Aug 30, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants