投放应用程序时,缩小React js中的文件大小

时间:2019-10-17 11:34:51

标签: react-redux webpack-dev-server

我是React + redux的新手,我正在开发一个应用程序,我将其卡在某个地方,每当我运行npm run serve命令时,它都会生成一个名为commons.js(大小为9 mb)的文件,这样会花费太多时间需要加载的时间,如果有人在互联网连接缓慢的情况下打开网址,我想知道有什么方法可以减小大小。   我使用了优化,splitChunks来减小文件大小 下面是依赖项

"uglifyjs-webpack-plugin": "^1.1.2",
"url-loader": "^2.1.0",
"webpack": "4.31.0",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "3.3.1"

下面是webpack cofig代码

const config = {
  ...webpackAlias,
  mode: modeAlias,
  optimization: {
    splitChunks: {
      cacheGroups: {
        commons: {
          minChunks: 2,
          name: 'commons',
          chunks: 'all'
        },
      },
    }
  },
  context: __dirname,
  entry,
  devtool,
  output: {
    path: outputPath,
    publicPath: '/webpack/static/',
    filename: '[name].js',
  },
  devServer: {
    contentBase: outputPath,
    port: 44444,
    publicPath: DEV_SERVER_PUBLIC_PATH,
    stats: {
      errors: true,
      warnings: true,
      assets: false,
      chunks: true,
      chunkGroups: true,
      chunkModules: true,
      chunkOrigins: true,
      builtAt: false,
      cached: false,
      timings: false,
      outputPath: false,
      modules: true,
      entrypoints: true,
    },
    headers: {
      "Access-Control-Allow-Origin": "\*",
    }
  },

0 个答案:

没有答案