Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large build size in production #107

Closed
benhunt29 opened this issue Mar 31, 2017 · 8 comments
Closed

Large build size in production #107

benhunt29 opened this issue Mar 31, 2017 · 8 comments
Assignees

Comments

@benhunt29
Copy link

Any idea why I'm getting such a large vendor bundle size (1.24MB) when including this library? Using webpack-bundle-analyzer shows this library is the main contributor to the large file size.

I'm using webpack 2 and here's my config. I'm relatively new to webpack and definitely new to this library so please forgive me if I'm doing something stupid.

const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
const WebpackMd5Hash = require('webpack-md5-hash')

const sourcePath = path.join(__dirname, './src')

module.exports = function (env) {
  const nodeEnv = env && env.prod ? 'production' : 'development'
  const isProd = nodeEnv === 'production'
  const cssOutputPath = isProd ? './styles/[name].[hash].css' : './styles/[name].css'
  const ExtractCSS = new ExtractTextPlugin(cssOutputPath)

  const plugins = [
    new webpack.EnvironmentPlugin({
      NODE_ENV: nodeEnv
    }),
    new webpack.NamedModulesPlugin(),
    new HtmlWebpackPlugin({
      template: path.join(__dirname, './src/index.html')
    }),
    new CommonsChunkPlugin({
      name: 'vendor',
      minChunks: ({ resource }) => /node_modules/.test(resource)
    }),
    new webpack.optimize.CommonsChunkPlugin('manifest'),
    new WebpackMd5Hash()
  ]

  const scssLoader = isProd ? ExtractCSS.extract([
    'css-loader',
    'sass-loader'
  ]) : [
    'style-loader',
    'css-loader',
    'sass-loader'
  ]

  const cssLoader = isProd ? ExtractCSS.extract([
    {
      loader: 'css-loader',
      options: {
        modules: true,
        sourceMap: true,
        importLoaders: 1,
        localIdentName: '[name]--[local]--[hash:base64:8]'
      }
    },
    'postcss-loader'
  ]) : [
    'style-loader',
    {
      loader: 'css-loader',
      options: {
        modules: true,
        sourceMap: true,
        importLoaders: 1,
        localIdentName: '[name]--[local]--[hash:base64:8]'
      }
    },
    'postcss-loader'
  ]

  if (isProd) {
    plugins.push(
      new webpack.LoaderOptionsPlugin({
        minimize: true,
        debug: false
      }),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false,
          screw_ie8: true,
          conditionals: true,
          unused: true,
          comparisons: true,
          sequences: true,
          dead_code: true,
          evaluate: true,
          if_return: true,
          join_vars: true
        },
        output: {
          comments: false
        }
      }),
      ExtractCSS
    )
  } else {
    plugins.push(
      new webpack.HotModuleReplacementPlugin()
    )
  }

  return {
    devtool: isProd ? 'source-map' : 'eval',
    context: sourcePath,
    entry: {
      app: './app/index.js'
    },
    output: {
      path: path.join(__dirname, './dist'),
      filename: './scripts/[name]-[hash].js',
      chunkFilename: './scripts/[name]-[hash].js',
      publicPath: '/'
    },
    module: {
      rules: [
        {
          test: /\.(jpe?g|gif|png|svg|woff|ttf|wav|mp3)$/,
          exclude: /node_modules/,
          use: {
            loader: 'url-loader',
            options: { limit: 10000 }
          }
        },
        {
          test: /\.scss$/,
          use: scssLoader
        },
        {
          test: /\.css$/,
          use: cssLoader
        },
        {
          test: /\.(js|jsx)$/,
          exclude: /node_modules/,
          use: [
            'babel-loader'
          ]
        }
      ]
    },
    resolve: {
      extensions: ['.webpack-loader.js', '.web-loader.js', '.loader.js', '.js', '.jsx', '.scss', '.css'],
      modules: [
        path.resolve(__dirname, 'node_modules'),
        sourcePath
      ]
    },

    plugins,

    performance: isProd && {
      maxAssetSize: 100,
      maxEntrypointSize: 300,
      hints: 'warning'
    },

    stats: {
      colors: {
        green: '\u001b[32m'
      }
    },

    devServer: {
      contentBase: './',
      historyApiFallback: true,
      port: 3000,
      compress: isProd,
      inline: !isProd,
      hot: !isProd,
      proxy: {
        '/api': {
          target: 'http://localhost:8080',
          secure: false
        },
        stats: {
          assets: true,
          children: false,
          chunks: false,
          hash: false,
          modules: false,
          publicPath: false,
          timings: true,
          version: false,
          warnings: true,
          colors: {
            green: '\u001b[32m'
          }
        }
      }
    }
  }
}
@prescottprue
Copy link
Owner

Are you sure that you are doing a -p build of webpack (i.e. NODE_ENV is "production")?

The built version of the library is only roughly 750kb unminified and 440kb minified, so it shouldn't increase your bundle size to that degree.

Going to create a project using webpack 2 and see if I can replicate the size.

@benhunt29
Copy link
Author

Yep, I've confirmed that inside my webpack config process.env.NODE_ENV is indeed 'production'

@prescottprue
Copy link
Owner

@benhunt29 Which version are you using?

Going to attempt to build similarly and analyze it myself. Guessing it may be due to immutable and firebase being included in the bundle that is being included as well (they are dependencies). It might

Plans for v2.0.0 include removing the usage of immutable, which should help considerably. Other than that, totally open to suggestions for shrinking the size.

@benhunt29
Copy link
Author

@prescottprue I'm using 1.4.0-beta.3. Thanks for looking into this!

@prescottprue
Copy link
Owner

prescottprue commented Apr 5, 2017

Currently

@benhunt29 I used the bundle analyzer myself, and it yielded the following from the minified bundle:

image

Plan

Removing immutable (as is the plan in v2.0.0) should help to shrink the size, but I think it is still mostly Firebase.

Maybe there is a way to modify your webpack config to point directly to the source or es5ified source (the js:next, module, or main fields of the package file) so that dependencies do not count for the size of the library itself.

v1.4.0-rc.1 includes the build:size npm script (run using npm run build:size) that generates the size report shown above. I am planning on using this script to measure any progress on shrinking bundle size.

Will continue to post any updates.

prescottprue added a commit that referenced this issue Apr 5, 2017
* #107 - `build:size` npm script added to generate size report for minified bundle
* #109 - Firebase version is not fixed - all v1.4.0-* versions use `^` on firebase
* Multiple Dependencies and Dev Dependencies updated (including `firebase` and `jwt-decode`)
* Yarn file updated
* Compose tests improved promise handling (better use of `chai-as-promised`)
* Linting removed from updated `eslint-config-standard` rules
@prescottprue prescottprue self-assigned this Apr 5, 2017
@prescottprue
Copy link
Owner

prescottprue commented May 6, 2017

Just as an update: v1.4.0-rc.2 might also shrink the size just a bit.

It would be good to know what relative size you are aiming for as well (keeping in mind that this includes firebase's library as well).

@benhunt29
Copy link
Author

great, I'll check it out. thanks!

prescottprue added a commit that referenced this issue May 17, 2017
#### Features
* `react-native` support (including [complete example](https://github.com/prescottprue/react-redux-firebase/tree/v1.4.0-beta/examples/complete/react-native) app as well as a [create your own recipe](/docs/recipes/react-native.md))
* Server Side Rendering Support ([#72](#72))
* Support for Boilerplates ([#53](#53))
* `pushWithMeta`, `setWithMeta`, and `updateWithMeta` methods added - write to firebase with createdAt/updatedAt and createdBy/updatedBy
* Fix for `unWatchEvent` helper dispatch mapping (#82)
* `populatedDataToJS` triggers `isLoaded` to be true only when all data is populated (instead of once for unpopulated data) [#121](#121)
* Support for `provider.setCustomParameters` on external auth providers (i.e. `provider.setCustomParameters({ prompt: 'select_account' })`)
* `notParsed` query param option added for not parsing when using `equalTo` (for searching numbers stored as strings)
* `profileParamsToPopulate` now works for `$key: true` lists (thanks @fej-snikduj)
* `onRedirectResult` config option added (runs when redirect result occurs)


#### Enhancements/Fixes
* Improvements to Material Example
  * Projects route is now protected (using `UserIsAuthenticated` HOC from `utils/router`)
  * Todos list only displays first 8 (first at the top) - shows using ordering query params
  * Most main routes are now sync (more simple)
* Firebase Library dependency updated to [`v3.9.0`](https://firebase.google.com/support/release-notes/js)
* Fix for `unWatchEvent` helper dispatch mapping ([#82](#82))
* Firebase version is no longer fixed ([#109](#109))
* Only used parts of Firebase Library imported (shrinks bundle size)
* `build:size` npm script added to generate size report for minified bundle ([#107](#107))
* `user` and `credential` are now returned from login method (solves [#106](#106))
* `yarn.lock` file added
* Compose tests improved promise handling (better use of chai-as-promised)
* `profileParamsToPopulate` now accepts `key: true` lists - thanks [@fej-snikduj](https://github.com/fej-snikduj)
prescottprue added a commit that referenced this issue May 17, 2017
* `react-native` support (including [complete example](https://github.com/prescottprue/react-redux-firebase/tree/v1.4.0-beta/examples/complete/react-native) app as well as a [create your own recipe](/docs/recipes/react-native.md))
* Server Side Rendering Support ([#72](#72))
* Support for Boilerplates ([#53](#53))
* `pushWithMeta`, `setWithMeta`, and `updateWithMeta` methods added - write to firebase with createdAt/updatedAt and createdBy/updatedBy
* Fix for `unWatchEvent` helper dispatch mapping (#82)
* `populatedDataToJS` triggers `isLoaded` to be true only when all data is populated (instead of once for unpopulated data) [#121](#121)
* Support for `provider.setCustomParameters` on external auth providers (i.e. `provider.setCustomParameters({ prompt: 'select_account' })`)
* `notParsed` query param option added for not parsing when using `equalTo` (for searching numbers stored as strings)
* `profileParamsToPopulate` now works for `$key: true` lists (thanks @fej-snikduj)
* `onRedirectResult` config option added (runs when redirect result occurs)

* Improvements to Material Example
  * Projects route is now protected (using `UserIsAuthenticated` HOC from `utils/router`)
  * Todos list only displays first 8 (first at the top) - shows using ordering query params
  * Most main routes are now sync (more simple)
* Firebase Library dependency updated to [`v3.9.0`](https://firebase.google.com/support/release-notes/js)
* Fix for `unWatchEvent` helper dispatch mapping ([#82](#82))
* Firebase version is no longer fixed ([#109](#109))
* Only used parts of Firebase Library imported (shrinks bundle size)
* `build:size` npm script added to generate size report for minified bundle ([#107](#107))
* `user` and `credential` are now returned from login method (solves [#106](#106))
* `yarn.lock` file added
* Compose tests improved promise handling (better use of chai-as-promised)
* `profileParamsToPopulate` now accepts `key: true` lists - thanks [@fej-snikduj](https://github.com/fej-snikduj)
@prescottprue
Copy link
Owner

v1.4.0 has been released with these size improvements and npm run build:size command (for checking the size of dependencies).

For those planning on posting another issue on shrinking size in the future: Please provide the relative size you are aiming for (please keep in mind that this size includes Firebase's library as well)

prescottprue pushed a commit that referenced this issue Jun 27, 2017
* Firebase is no longer a dependency (build size, native compatibility,
bundling for boilerplates, etc.) - #173, #131, #107
* Migration guide updated
* Roadmap updated with v2.0.0 and v1.5.0 info
@prescottprue prescottprue mentioned this issue Jul 3, 2017
6 tasks
prescottprue added a commit that referenced this issue Jul 4, 2017
### Features
* [X] Keeping data on logout - #125
* [X] Listeners now kept on state (follows byId/allIds pattern [from redux docs](http://redux.js.org/docs/recipes/reducers/UpdatingNormalizedData.html))
* [X] `ordered` reducer added for managing ordered state (`SET_ORDERED` no longer used)
* [X] `populate` works for profile (needed to remove share population logic)
* [X] Presence capability added to show currently logged in users and track user sessions (`presence` in config)
* [X]  Firebase is no longer a dependency (build size, native compatibility, bundling for boilerplates, etc.) - #173, #131, #107


### Fixes/Enhancements
* Drop support for passing Firebase instance
* Auto profile population removed (profile population will require using populate)
* `isLoaded` and `isEmpty` logic simplified
* Tests passing with new syntax (including reducers)
* Drop support and deprecation warning for `profileDecorator` (use `profileFactory`)
* Drop support and deprecation warning for `distpatchOnUnsetListener` (use `distpatchOnUnsetListener`, note incorrect spelling)
* Tests no longer skipped from linting
* Tons of other code simplifications
Tomoya32 added a commit to Tomoya32/react-redux-firebase that referenced this issue Aug 22, 2018
* `react-native` support (including [complete example](https://github.com/prescottprue/react-redux-firebase/tree/v1.4.0-beta/examples/complete/react-native) app as well as a [create your own recipe](/docs/recipes/react-native.md))
* Server Side Rendering Support ([#72](prescottprue/react-redux-firebase#72))
* Support for Boilerplates ([#53](prescottprue/react-redux-firebase#53))
* `pushWithMeta`, `setWithMeta`, and `updateWithMeta` methods added - write to firebase with createdAt/updatedAt and createdBy/updatedBy
* Fix for `unWatchEvent` helper dispatch mapping (#82)
* `populatedDataToJS` triggers `isLoaded` to be true only when all data is populated (instead of once for unpopulated data) [#121](prescottprue/react-redux-firebase#121)
* Support for `provider.setCustomParameters` on external auth providers (i.e. `provider.setCustomParameters({ prompt: 'select_account' })`)
* `notParsed` query param option added for not parsing when using `equalTo` (for searching numbers stored as strings)
* `profileParamsToPopulate` now works for `$key: true` lists (thanks @fej-snikduj)
* `onRedirectResult` config option added (runs when redirect result occurs)

* Improvements to Material Example
  * Projects route is now protected (using `UserIsAuthenticated` HOC from `utils/router`)
  * Todos list only displays first 8 (first at the top) - shows using ordering query params
  * Most main routes are now sync (more simple)
* Firebase Library dependency updated to [`v3.9.0`](https://firebase.google.com/support/release-notes/js)
* Fix for `unWatchEvent` helper dispatch mapping ([#82](prescottprue/react-redux-firebase#82))
* Firebase version is no longer fixed ([#109](prescottprue/react-redux-firebase#109))
* Only used parts of Firebase Library imported (shrinks bundle size)
* `build:size` npm script added to generate size report for minified bundle ([#107](prescottprue/react-redux-firebase#107))
* `user` and `credential` are now returned from login method (solves [#106](prescottprue/react-redux-firebase#106))
* `yarn.lock` file added
* Compose tests improved promise handling (better use of chai-as-promised)
* `profileParamsToPopulate` now accepts `key: true` lists - thanks [@fej-snikduj](https://github.com/fej-snikduj)
mirdavion pushed a commit to mirdavion/react-redux-firebase that referenced this issue Mar 18, 2021
* `react-native` support (including [complete example](https://github.com/prescottprue/react-redux-firebase/tree/v1.4.0-beta/examples/complete/react-native) app as well as a [create your own recipe](/docs/recipes/react-native.md))
* Server Side Rendering Support ([#72](prescottprue/react-redux-firebase#72))
* Support for Boilerplates ([#53](prescottprue/react-redux-firebase#53))
* `pushWithMeta`, `setWithMeta`, and `updateWithMeta` methods added - write to firebase with createdAt/updatedAt and createdBy/updatedBy
* Fix for `unWatchEvent` helper dispatch mapping (#82)
* `populatedDataToJS` triggers `isLoaded` to be true only when all data is populated (instead of once for unpopulated data) [#121](prescottprue/react-redux-firebase#121)
* Support for `provider.setCustomParameters` on external auth providers (i.e. `provider.setCustomParameters({ prompt: 'select_account' })`)
* `notParsed` query param option added for not parsing when using `equalTo` (for searching numbers stored as strings)
* `profileParamsToPopulate` now works for `$key: true` lists (thanks @fej-snikduj)
* `onRedirectResult` config option added (runs when redirect result occurs)

* Improvements to Material Example
  * Projects route is now protected (using `UserIsAuthenticated` HOC from `utils/router`)
  * Todos list only displays first 8 (first at the top) - shows using ordering query params
  * Most main routes are now sync (more simple)
* Firebase Library dependency updated to [`v3.9.0`](https://firebase.google.com/support/release-notes/js)
* Fix for `unWatchEvent` helper dispatch mapping ([#82](prescottprue/react-redux-firebase#82))
* Firebase version is no longer fixed ([#109](prescottprue/react-redux-firebase#109))
* Only used parts of Firebase Library imported (shrinks bundle size)
* `build:size` npm script added to generate size report for minified bundle ([#107](prescottprue/react-redux-firebase#107))
* `user` and `credential` are now returned from login method (solves [#106](prescottprue/react-redux-firebase#106))
* `yarn.lock` file added
* Compose tests improved promise handling (better use of chai-as-promised)
* `profileParamsToPopulate` now accepts `key: true` lists - thanks [@fej-snikduj](https://github.com/fej-snikduj)
prodev90 added a commit to prodev90/react-redux-firebase-sample that referenced this issue Jan 4, 2023
* `react-native` support (including [complete example](https://github.com/prescottprue/react-redux-firebase/tree/v1.4.0-beta/examples/complete/react-native) app as well as a [create your own recipe](/docs/recipes/react-native.md))
* Server Side Rendering Support ([#72](prescottprue/react-redux-firebase#72))
* Support for Boilerplates ([#53](prescottprue/react-redux-firebase#53))
* `pushWithMeta`, `setWithMeta`, and `updateWithMeta` methods added - write to firebase with createdAt/updatedAt and createdBy/updatedBy
* Fix for `unWatchEvent` helper dispatch mapping (#82)
* `populatedDataToJS` triggers `isLoaded` to be true only when all data is populated (instead of once for unpopulated data) [#121](prescottprue/react-redux-firebase#121)
* Support for `provider.setCustomParameters` on external auth providers (i.e. `provider.setCustomParameters({ prompt: 'select_account' })`)
* `notParsed` query param option added for not parsing when using `equalTo` (for searching numbers stored as strings)
* `profileParamsToPopulate` now works for `$key: true` lists (thanks @fej-snikduj)
* `onRedirectResult` config option added (runs when redirect result occurs)

* Improvements to Material Example
  * Projects route is now protected (using `UserIsAuthenticated` HOC from `utils/router`)
  * Todos list only displays first 8 (first at the top) - shows using ordering query params
  * Most main routes are now sync (more simple)
* Firebase Library dependency updated to [`v3.9.0`](https://firebase.google.com/support/release-notes/js)
* Fix for `unWatchEvent` helper dispatch mapping ([#82](prescottprue/react-redux-firebase#82))
* Firebase version is no longer fixed ([#109](prescottprue/react-redux-firebase#109))
* Only used parts of Firebase Library imported (shrinks bundle size)
* `build:size` npm script added to generate size report for minified bundle ([#107](prescottprue/react-redux-firebase#107))
* `user` and `credential` are now returned from login method (solves [#106](prescottprue/react-redux-firebase#106))
* `yarn.lock` file added
* Compose tests improved promise handling (better use of chai-as-promised)
* `profileParamsToPopulate` now accepts `key: true` lists - thanks [@fej-snikduj](https://github.com/fej-snikduj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants