Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-dom blowing out webpack bundle size MASSIVELY

This has got to be one of the strangest issues with webpack i have ever come across...

Check out this bundle breakdown: enter image description here react 116.01KB - fair enough

react-dom 533.24KB - seriously WTF

I thought it may be a corruption in my dependencies but nuking node_modules and reinstalling doesn't have any effect. I guess it's something to do with the way webpack is bundling it but i'm lost for ideas. The way i'm handing .js imports is pretty stock standard.

// webpack.config.js
const path = require('path');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const Dashboard = require('webpack-dashboard');
const DashboardPlugin = require('webpack-dashboard/plugin');

const dashboard = new Dashboard();

module.exports = {
  context: path.join(__dirname, 'src'),
  entry: {
    bundle: './index.js',
  },
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'build'),
  },
  module: {
    rules: [
      {
        test: /\.html$/,
        use: 'file-loader?name=[name].[ext]',
      },
      {
        test: /.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            'css-loader',
            'postcss-loader',
          ],
        }),
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: 'babel-loader',
      },
    ],
  },
  plugins: [
    // new BundleAnalyzerPlugin(),
    new ExtractTextPlugin('styles.css'),
    new DashboardPlugin(dashboard.setData),
  ],
  devServer: {
    quiet: true,
  },
};

// .babelrc
{
  "presets": [
    "react",
    "es2015"
  ],
  "plugins": ["transform-object-rest-spread"]
}
like image 923
Toby Flemming Avatar asked Mar 10 '17 10:03

Toby Flemming


3 Answers

I had to change my webpack.config.js, from

devtool: 'inline-source-map'

enter image description here

to

devtool: 'source-map'

enter image description here

Now it generates a much smaller .js + a separate .js.map file, for each of the chunks.

Notice the JS size is even less than react-dom.production.min.js in node_modules: enter image description here

like image 158
Neolisk Avatar answered Nov 17 '22 10:11

Neolisk


http://elijahmanor.com/react-file-size/

In v15.4.0 the file size of react-dom grew from 1.17kB to 619.05kB. Which means my webpack setup isn't doing anything wrong bundling files. The reason why this module grew so large is because code was transferred from the react module.

like image 42
Toby Flemming Avatar answered Nov 17 '22 11:11

Toby Flemming


If you look into the corresponding folders under the node_modules folder, and note the file sizes, you'll see that there's nothing to be surprised about:

react

react-dom

That is, the size of the bundle grows noticeably because the size of react-dom.js is large.

like image 2
m1kael Avatar answered Nov 17 '22 10:11

m1kael