DEV Community

Adeel Imran
Adeel Imran

Posted on

Vendor splitting using webpack 4

In your webpack config file simply add this piece of code

optimization: {
    minimizer: [
      new OptimizeCSSAssetsPlugin(),
    ],
    // Automatically split vendor and commons
    // https://twitter.com/wSokra/status/969633336732905474
    // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
    splitChunks: {
      chunks: 'all',
      name: false,
    },
    // Keep the runtime chunk seperated to enable long term caching
    // https://twitter.com/wSokra/status/969679223278505985
    runtimeChunk: true,
  },
Enter fullscreen mode Exit fullscreen mode

You will need to have this webpack extension https://github.com/NMFR/optimize-css-assets-webpack-plugin

Top comments (0)