The content of this gist has been superseded by a new proper plugin for webpack: https://github.com/gilmoreorless/moment-timezone-data-webpack-plugin
The original contents of the gist are kept below for context, but I encourage people to use the plugin instead.
This is a custom helper script I wrote for a project’s Webpack build. It reduces the amount of time zone definition data loaded by moment-timezone
. This helps reduce the size of the JS bundle loaded in a browser.
The project only needed time zone data for Australia and New Zealand from 2016 onwards. Stripping down the data as much as possible reduced the gzipped data size from 23KB to 0.4KB (and the raw, unminified size went from 176KB to 1.3KB).
This script is provided here as an interim answer to iamakulov/moment-locales-webpack-plugin#17
I intend to turn this into a proper Webpack plugin with greater flexibility (and actual tests). But this raw script can be helpful to some people until then.
The file exports a new NormalModuleReplacementPlugin
instance based on the data configuration. Therefore it can be require()
d directly into your Webpack config file:
// webpack.config.js
module.exports = {
// [your standard Webpack config goes here]
plugins: [
require('./exclude-moment-timezone-data'),
],
};