vuejs-templates / webpack

A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.
MIT License
9.7k stars 4.38k forks source link

the vendor file changed hash when I add echart to children chunk #1443

Open InvincibleJun opened 6 years ago

InvincibleJun commented 6 years ago

Version

2.9.3

Reproduction link

https://github.com/InvincibleJun/demo

Node and OS info

Node 8.9.1 / npm 5.5.1 / Windows 10

Steps to reproduce

for example, I have four pages which use `() => import and use echarts. when all pages use echarts and I packed, it will make a extra chunk file. Then I only use echarts in two pages and I packed, the vendor.[hash].js is different as old file. it ‘s so terrible.

CommonsChunkPlugin options as follows or see the demo

    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      minChunks (module) {
        // any required modules inside node_modules are extracted to vendor
        return (
          module.resource &&
          /\.js$/.test(module.resource) &&
          module.resource.indexOf(
            path.join(__dirname, '../node_modules')
          ) === 0
        )
      }
    }),
    // extract webpack runtime and module manifest to its own file in order to
    // prevent vendor hash from being updated whenever app bundle is updated
    new webpack.optimize.CommonsChunkPlugin({
      name: 'manifest',
      minChunks: Infinity
    }),
    // This instance extracts shared chunks from code splitted chunks and bundles them
    // in a separate chunk, similar to the vendor chunk
    // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
    new webpack.optimize.CommonsChunkPlugin({
      name: 'app',
      async: 'vendor-async',
      children: true,
      minChunks: 3
    })

What is expected?

the vendor hash not changed

What is actually happening?

the hash changed

heinzdmx commented 6 years ago

I don't think this issue tracker is meant to be used as a support option. But itsn't it because of minChunks: 3 in CommonsChunkPlugin. It essentially will only placed it in a seperate chunk if 3 chunks uses it. If only 2 it will not do that. If you setr minChunks to 2 that would probably do it for you. But that could have other consequences.

InvincibleJun commented 6 years ago

I don't think this issue tracker is meant to be used as a support option. But itsn't it because of minChunks: 3 in CommonsChunkPlugin. It essentially will only placed it in a seperate chunk if 3 chunks uses it. If only 2 it will not do that. If you setr minChunks to 2 that would probably do it for you. But that could have other consequences.

the vendor file size did not changed, but it hash value changed.