LoginSignup
1
1

More than 3 years have passed since last update.

Webpack4 splitChunks の対象を一部に絞る

Posted at

webpack4で新たに追加されたoptimization.splitChunksの基本的な使い方はこちらの記事に譲るとして、
splitChunksの細かいところについて。

よくある書き方

module.exports = {
  ...
  optimization: {
    splitChunks: {
      cacheGroups: {
        vendor: {
          test: /node_modules/,
          name: 'vendor',
          chunks: 'initial',
        }
      }
    }
  }
};

こうすることでnode_modules配下をvendor.bundle.jsというかたちで分けることができる。

対象を絞る

const moduleList = ["@babel/polyfill", "react", "react-dom"];

module.exports = {
  ...
  optimization: {
    splitChunks: {
      cacheGroups: {
        vendor: {
          test: new RegExp(
            `[\\/]node_modules[\\/](${moduleList.join("|")})[\\/]`
          ),
          name: 'vendor',
          chunks: 'initial',
        }
      }
    }
  }
};

こうすることで、splitしたいmoduleを一部に絞ることができる。

1
1
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
1
1