Problems in webpack4.x configuration

directory structure

webpack.config.js

index.js


dist



webpack,dist

< hr > < hr > < H2 > question: < / H2 >

1. After optimization.cacheGroups is added, chunkFilename in the mini-css-extract-plugin configuration replaces filename,. Does cacheGroups cause css to become an asynchronously loaded module?
2. Why a new style.js? is generated Because index.js refers to css?. And went to the folder async of the asynchronous module.

what is the principle of the ball solution? I feel that webpack4 is more difficult to use than 3

Sep.23,2021

cacheGroups.styles.test should be changed to /\ .css $/ . In this way, it will not be overwritten, and styles.js will not generate


.
optimization: {
  splitChunks: {
    cacheGroups: {
      vendor: {
        test: /[\\/]node_modules[\\/].*\.js$/,
        name: 'vendors',
        chunks: 'all',
      },
    },
  },
},

just write it this way.

found in mini-css-extract-plugin github issues.
Menu