0

The following config cannot generate commons chunk if it uses nodeExternals, my question is how to chunk vendor codes while using nodeExternals?

webpack.config.js

const nodeExternals = require('webpack-node-externals');
module.exports = {
  name: 'server',
  target: 'node',
  mode: 'development',
  entry: './index.js',
  optimization: {
    runtimeChunk: {
      name: 'runtime',
    },
    splitChunks: {
      chunks: 'all',
      cacheGroups: {
        commons: {
          chunks: 'all',
          test: /[\\/]node_modules[\\/]/,
          enforce: true,
        },
      },
    },
  },

  externals: [nodeExternals()],

  module: {
    rules: [
      {
        oneOf: [
          {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            loader: require.resolve('babel-loader'),
          },
        ],
      },
    ],
  },
};
felixmosh
  • 32,615
  • 9
  • 69
  • 88
yuyicman
  • 95
  • 1
  • 8
  • what is the reason for using nodeExternals & vendor chunks? – felixmosh Jul 06 '20 at 17:29
  • The reason is a bit complex, I'm doing a function for runtime module loading, it needs a clear chunk with no entry or runtime modules, then I stuck here – yuyicman Jul 07 '20 at 02:07
  • I try to remove test in splitChunks, then webpack will split entry codes and leave external modules to main.js, but it will cause dependency problem – yuyicman Jul 07 '20 at 02:22

0 Answers0