webpack.dev.babel.js 2.39 KB
/**
 * DEVELOPMENT WEBPACK CONFIGURATION
 */

const path = require('path');
const CircularDependencyPlugin = require('circular-dependency-plugin');
module.exports = require('./webpack.base.babel')({
  mode: 'development',

  // Add hot reloading in development
  entry: [
    'webpack-hot-middleware/client?reload=true',
    path.join(process.cwd(), 'src/app.js'), // Start with js/app.js
  ],
  optimization: {
    // namedModules: true,
    // namedChunks: true,
    chunkIds: 'named',
    runtimeChunk: {
      name: 'runtime',
    },
    splitChunks: {
      name: false,
      // eslint-disable-next-line no-irregular-whitespace
      chunks: 'all', // all(全部), async(异步的模块),initial(同步的模块)
      // eslint-disable-next-line no-irregular-whitespace
      minSize: 20000, // 表示文件大于1k的时候才对它进行打包
      // eslint-disable-next-line no-irregular-whitespace
      minChunks: 2, // 当某个模块满足minChunks引用次数时,才会被打包。
      // eslint-disable-next-line no-irregular-whitespace
      maxAsyncRequests: 5, // 在打包某个模块的时候,最多分成5个chunk,多余的会合到最后一个chunk中
      maxInitialRequests: Infinity,
      automaticNameDelimiter: '~', // 当vendors或者default中的filename不填时,打包出来的文件名就会带~
      cacheGroups: {
        default: false,
        vendors: {
          // eslint-disable-next-line no-irregular-whitespace
          // 将从node_modules中引入的模块统一打包到common.js文件中
          name: 'common',
          chunks: 'all',
          minChunks: 2,
          test: /[\\/]node_modules[\\/]/,
        },
        // styles: {
        //   // css统一打包到common.css文件中
        //   name: 'common',
        //   chunks: 'all',
        //   minChunks: 2,
        //   test: /\.(css|less|scss|stylus)$/,
        //   enforce: true,
        //   priority: 50,
        // },
      },
    },
  },
  plugins: [
    // new CircularDependencyPlugin({
    //   exclude: /node_modules/,
    //   include: /src/,
    //   failOnError: false,
    //   allowAsyncCycles: false,
    //   cwd: process.cwd(),
    // }),
  ],
  devtool: 'cheap-module-source-map',
  node: {
    setImmediate: false,
    process: 'mock',
    dgram: 'empty',
    fs: 'empty',
    net: 'empty',
    tls: 'empty',
    child_process: 'empty',
  },
  performance: {
    hints: false,
  },
});