A
A
amiznikov2019-05-24 15:43:17
JavaScript
amiznikov, 2019-05-24 15:43:17

How to merge all common modules into one of the chunks?

Hello everyone, there are multiple entry points:

webpackConfig.entry = {
{
   "core": ["./src/app/main.js", jquery],
   "chunkA": "./src/chunkA/chunkA.js",
   "chunkB": "./src/chunkB/chunkB.js",
}

here, all chunks contain a module - jquery (a regular package from npm), I would like this module to be in only one main.js chunk, because the rest of the chunks are connected after it.
Previously, in webpack3 it was solved like this:
webpackConfig.entry = {
{
   "core": ["./src/app/main.js", jquery],
   "chunkA": "./src/chunkA/chunkA.js",
   "chunkB": "./src/chunkB/chunkB.js",
}

....
new webpack.optimize.CommonsChunkPlugin({name: 'core'}),
...

let output = {
  path: path.resolve(__dirname, 'dist'),
  filename,
  library: ['Module', '[name]'],
}

Thank you all for any hint :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2019-05-24
@Robur

https://webpack.js.org/guides/code-splitting/#root - "Prevent Duplication" section

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question