Webpack生产模式

时间:2018-10-19 08:26:28

标签: reactjs webpack

这是我的webpack.config.js

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: `[name].bundle.js`,
    chunkFilename: `[name].bundle.js`
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
         new webpack.optimize.ModuleConcatenationPlugin(),
    new webpack.DefinePlugin({
        'process.env': {
                'NODE_ENV': JSON.stringify('production')


        }
            }),  
            new webpack.optimize.CommonsChunkPlugin({
   ....      }
      })
      ]...

};

我将NODE_ENV设置为生产,但是我的网站显示为红色,表示它仍处于开发模式。怎么了? 我如何最小化我的建筑?

  "webpack": "^3.10.0",
    "webpack-bundle-analyzer": "^2.11.1",
    "webpack-dev-middleware": "^1.12.0",
    "webpack-hot-middleware": "^2.22.1"

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用

webpack -p

这将减小捆绑包的大小并在生产模式下捆绑它。