Mini-css-extract-plugin: "Extracting all CSS in a single file" does not work when using a `vendor` cache group

Created on 1 Aug 2018  ·  10Comments  ·  Source: webpack-contrib/mini-css-extract-plugin

This is my cache group config. I'm after

        cacheGroups: {
          default: false,
          vendors: false,
          vendor: {
            test: /[\\/]node_modules[\\/]/,
            name: 'vendor',
            chunks: 'all',
            enforce: true
          },
          styles: {
            name: 'bundle',
            test: /\.css$/,
            chunks: 'all',
            priority: 1000,
            enforce: true
          }
        }

Plugin:

new MiniCssExtractPlugin({ filename: 'bundle.css' }),

The result is 2 files, bundle.css and 1.bundle.css. If I remove the vendor group, I only get bundle.css which is what I want, but in doing so I end up with a single JS file which is not optimal.

I'd like a single bundle.css while keeping separate vendor.js and app.js. 😄

patch 4 (inconvenient) docs

Most helpful comment

I had something similar which i solved differently:

            splitChunks: {
                cacheGroups: {
                    vendor: {
                        test: /(node_modules|vendors).+(?<!css)$/,
                        name: 'vendor',
                        chunks: 'all'
                    }
                }
            }

The vendor bundle excludes all files with .css explicitly.

All 10 comments

@jeffijoe PR welcome to fix docs

@evilebottnawi Does this mean that this works as intended? I'd be more than happy to submit a PR to the docs, but with a work-around for the desired behavior. 😄

It doesn't work even without vendor for me. Still have one css file for one chunk.

I had something similar which i solved differently:

            splitChunks: {
                cacheGroups: {
                    vendor: {
                        test: /(node_modules|vendors).+(?<!css)$/,
                        name: 'vendor',
                        chunks: 'all'
                    }
                }
            }

The vendor bundle excludes all files with .css explicitly.

Use something like this:

test: (m) => {
    const name = module.nameForCondition();
    return /(node_modules|vendors)/.test(name) && !(/\.css$/.test(name)),
}

For vendor group, because you extract to vendor all what inside node_modules

Is it necessary to package all the CSS files together?
I think the (cacheGroups>minSize,maxSize) should still need to be configured...
we don't need a large css file...

the reasons i'm doing this is because of the same-domain-concurrent-connection-limit, too many css files(which is loaded before all js files) will delay the loading of subsequent js files...

!(/.css$/.test(name)),

the trailing comma will cause syntax error

We extract to atomic css, but also running into this issue. We end up with a bunch of chunks of css with many duplicate styles, which actually degrades runtime perf as well as bundle size, so a bit more than inconvenient... would take a stab at this but webpack plugins are really hard to do right.

@natew because bundling is not easy, can you provide example, I will look at this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TheHolyWaffle picture TheHolyWaffle  ·  4Comments

septs picture septs  ·  3Comments

dmitrybelyakov picture dmitrybelyakov  ·  3Comments

BODhaha picture BODhaha  ·  3Comments

dstarosta picture dstarosta  ·  3Comments