LoginSignup
4
6

More than 5 years have passed since last update.

Webpackでnode_modules配下のライブラリを自動でCommonsChunkPluginに指定して出力

Last updated at Posted at 2017-08-17

WEB+DB PRESS Vol.99のWebpack2特集を読んでいてCommonsChunkPluginの説明が物足りなかったので書いてみた。
偉そうなこと言ってますが実は公式ドキュメントに普通に書いてあるものをコピペしただけです。

minChunks でnode_modules配下のライブラリかどうか判別してvendor.jsにぶっこんで吐き出します。

使用するモジュール

・Webpack (3.0.0)

Webpack設定

plugins: [
  new webpack.optimize.CommonsChunkPlugin({
    name: "vendor",
    minChunks: function(module){
      return module.context && module.context.indexOf("node_modules") !== -1;
    }
  })
]

公式ドキュメント

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6