Skip to content

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

@lsycxyj

Description

@lsycxyj

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.

Activity

alexander-akait

alexander-akait commented on Mar 28, 2019

@alexander-akait
Member

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

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

jcreamer898

jcreamer898 commented on Apr 24, 2019

@jcreamer898

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

lsycxyj commented on Jul 21, 2019

@lsycxyj
Author

@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

yanguoyu commented on Aug 29, 2019

@yanguoyu

image

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

lsycxyj

lsycxyj commented on Aug 29, 2019

@lsycxyj
Author

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

yanguoyu commented on Aug 29, 2019

@yanguoyu

is this not your want?

lsycxyj

lsycxyj commented on Aug 30, 2019

@lsycxyj
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jcreamer898@lsycxyj@alexander-akait@yanguoyu

        Issue actions

          Question: Is there any way to only extract the css files from initial chunk? · Issue #369 · webpack-contrib/mini-css-extract-plugin