Skip to content

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

Closed
@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.

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

    Issue actions