2

So this is my web pack:

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

module.exports = {
  entry: {
    event: './widgets/events/app.js'
  },
  output: {
    path: './dist',
    filename: '[name].widget.js'
  },
  target: 'web',
  node: {
    console: true,
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  },
  externals: [
    {
      'cls-bluebird': true
    }
  ],
  plugins: [
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false // https://github.com/webpack/webpack/issues/1496
      }
    })
  ],
  module: {
    loaders: [
      {
        test: /.js?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['es2015']
        }
      },
      {
        test: /\.marko$/,
        loader: 'marko-loader'
      }
    ]
  },
};

And I do:

"scripts": { "build": "eslint widgets && eslint helpers && webpack", "prod": "eslint widgets && eslint helpers && webpack -p --optimize-minimize" },

When I do npm run prod and then do a ls -lah on the dist/ directory I see:

ls -lah
total 2704
drwxr-xr-x   3 AdamBalan  staff   102B 17 Feb 13:28 .
drwxr-xr-x  13 AdamBalan  staff   442B 28 Feb 12:12 ..
-rw-r--r--   1 AdamBalan  staff   1.3M  7 Mar 16:05 event.widget.js

1.3 mb is way to big. I do use things like moment js, lodash and a couple other libraries. Is there any way to make this file smaller? Any other optimizations I'm missing?

Some one mentioned a concept of tree shaking, but every blog post sort of talks about it but doesn't really state how to do it.

Ideas?

TheWebs
  • 12,470
  • 30
  • 107
  • 211

1 Answers1

1

momentjs loads localization files. see this answer

lodash offers a babel plugin and webpack plugin that will load only what it needs instead of the whole library. see https://www.npmjs.com/package/babel-plugin-lodash and https://www.npmjs.com/package/lodash-webpack-plugin

Tree shaking is possible. See rollup example on how to use tree shaking. Applies to webpack.

Community
  • 1
  • 1
Rafael De Leon
  • 1,580
  • 1
  • 12
  • 11