Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Webpack ReactJS App so large?

I have followed as many tips as I can find in packaging my Webpack ReactJS app for production. Unfortunately, the file size is still 3MB. What am I doing wrong?

Here is my Webpack Config file:

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

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    './index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle-webpack.js',
    publicPath: './'
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('production')
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        screw_ie8: true,
        warnings: false
      }
    })
  ],
  module: {
    loaders: [
      {
        test: /\.js$/,
        loaders: [ 'babel' ],
        exclude: /node_modules/,
        include: __dirname
      },
      {
        test: /\.css$/,
        loader: "style-loader!css-loader" 
      },
      {test: /node_modules\/react-chatview/, loader: 'babel' }
    ]
  }
}

Any help would be greatly appreciated!

I use the following command to package it:

> NODE_ENV=production webpack -p 

I get the following output:

bundle-webpack.js  3.1 MB       0  [emitted]  main

Best,

Aaron

like image 885
Aaron Franco Avatar asked Jun 08 '26 01:06

Aaron Franco


1 Answers

Looks like you've still got a fair amount of dev stuff there, e.g. hot module replacement.

Take a look at webpack.config.prod.js at React Transform Boilerplate as a guide.

You may also be able to optimise your imports by including only the parts of the packages you need and leaving out the rest. See: Reduce Your bundle.js File Size By Doing This One Thing .

like image 89
David L. Walsh Avatar answered Jun 10 '26 18:06

David L. Walsh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!