Giter Club home page Giter Club logo

moment-locales-webpack-plugin's Introduction

moment-locales-webpack-plugin

npm Travis Greenkeeper badge

Easily remove unused Moment.js locales when building with webpack

Why

75% (160 minified KBs)¹ of Moment.js’ size are files used for localization. They are always included when you build your app with webpack.

You don’t need most of these files if your app is only available in a few languages. Use this plugin to strip these KBs and optimize the app!

¹ – tested with Moment.js 2.18.1

Install

npm install --save-dev moment-locales-webpack-plugin

Usage

// webpack.config.js
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');

module.exports = {
    plugins: [
        // To strip all locales except “en”
        new MomentLocalesPlugin(),

        // Or: To strip all locales except “en”, “es-us” and “ru”
        // (“en” is built into Moment and can’t be removed)
        new MomentLocalesPlugin({
            localesToKeep: ['es-us', 'ru'],
        }),
    ],
};

Plugin Options

localesToKeep: String[]

An array of locales to keep bundled (other locales would be removed).

Locale names follow Moment.js behavior – if a specific locale name (e.g. ru-ru) is absent, but a more generic locale (ru) is available, the generic one will be kept bundled.

ignoreInvalidLocales: Boolean

A flag to ignore invalid or unsupported locales in the localesToKeep array.

Be careful! A typo in the localesToKeep array with this flag enabled will silently exclude the desired locale from your bundle.

Related projects

Contributing

See CONTRIBUTING.md for how to contribute.

License

MIT © Ivan Akulov

moment-locales-webpack-plugin's People

Contributors

dependabot[bot] avatar greenkeeper[bot] avatar iamakulov avatar ihateelvis avatar jessevanassen avatar julesjanssen avatar mokkabonna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

moment-locales-webpack-plugin's Issues

moment/min/locales.js included in bundle _in addition_ to individual locale files

This is what my bundle analysis looks like before using your wonderful plugin:

image

And this is what it looks like after:

image

The question, of course, is why is that minified locales.js file being included in addition to the individual locale files?

I recognize that this isn't the responsibility of this plugin, but I'm curious if you have any insights or have seen this situation before. It's got to have something to do with one of my dependencies loading in moment in some dumb way.

Thanks.

An in-range update of webpack is breaking the build 🚨

The devDependency webpack was updated from 4.39.2 to 4.39.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v4.39.3

Bugfixes

  • fix a missing module in chunk caused by incorrect chunk graph generation of async chunks
Commits

The new version differs by 43 commits.

  • 94929a5 4.39.3
  • 6bf1868 Merge pull request #9635 from webpack/bugfix/9634
  • 83dd295 fixes #9634
  • 54519bd Merge pull request #9630 from webpack/dependabot/npm_and_yarn/eslint-utils-1.4.2
  • aa8d930 chore(deps): bump eslint-utils from 1.3.1 to 1.4.2
  • b16ca50 Merge pull request #9603 from noscripter/patch-1
  • 0601b12 Merge pull request #9623 from webpack/dependabot/npm_and_yarn/less-3.10.3
  • d56b9f8 chore(deps-dev): bump less from 3.10.2 to 3.10.3
  • 9dc49cf Merge pull request #9613 from shaodahong/optimize-eslint
  • 85421cd improve linting performance
  • 94d1768 resolve linting issues in test/helpers
  • 7ee8ca3 optimize code-lint config
  • 9b02c19 Merge pull request #9617 from webpack/dependabot/npm_and_yarn/eslint-plugin-jest-22.15.2
  • 45622a4 Merge pull request #9616 from webpack/dependabot/npm_and_yarn/less-3.10.2
  • 3c252ff Merge pull request #9608 from webpack/dependabot/npm_and_yarn/types/node-10.14.16

There are 43 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

locales in moment/dist/locale are still included

Hey, I'm sure I'm doing something wrong here, but even using this plugin with webpack and moment I am still getting the locales directory in my output.

When I look in the node_modules/moment directory, I see two locale folders.

One in the root, and one in dist/locale

I'm not sure why there are two, but no matter what I do the locales in node_moduels/moment/dist/locale are always included.

This seems to only ignore the root node_modules/moment/locale folder.

Any ideas? I'm at a bit of a loss. Thank you very much

Fetch additional locals if needed.

It would be cool if the loader had an option (just a boolean flag) that would inject a little runtime into the bundle that checks if the locale is present in the whitelist. If it's not, it would fetch an additional bundle containing the locale.

Not sure how this would work exactly so far as what would happen during the time that the main bundle loaded, but the fetch for the additional locale(s) is still in progress; does it just act like moment normally does and give some "locale missing" error, but once the fetch is complete give you the desired results? Or perhaps the module's evaluation is blocked until the locale is available (probably a terrible idea) or maybe an additional wrapper package for moment is created that exposes a promise which resolves when the desired locale is available—either imediately if the client's locale is in the whitelist, or after the fetch is complete.

Just a thought..

add relative node_modules position

if my webpack.the build process is not holding on current dir

the plugin can not find "moment"

try to add the "relative" option

in your source code

// you dont actrully know where truly moment module
// just give an option. require.resolve the moment relative position
moment = require('moment');

Webpack Warning: Critical dependency: the request of a dependency is an expression

[Edit: This seems to be related with WebPack in General, not with Angular]
When activating this module in an Angular 12 project, this results in a warning:

./node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:29834:15-36 - Warning: Critical dependency: the request of a dependency is an expression

When looking at webpack/webpack#196 this seems to be a webpack warning about a require statement using a dynamic path for loading, as this prohibits tree shaking. Maybe there is a way to implement this module's functionality without doing so?

An in-range update of webpack is breaking the build 🚨

The devDependency webpack was updated from 4.26.1 to 4.27.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v4.27.0

Features

  • When using functions as plugins they are now also called with the compiler as parameter
    • This make it possible to use arrow functions as plugins
  • splitChunks.maxSize now emits a warning when minSize > maxSize
  • Loaders have now access to a getResolve method to create their own resolver function with custom options

Bugfixes

  • splitChunks.cacheGroups.xxx.enforce now behaves as documented and enforce chunk creation
  • splitChunks.cacheGroups.xxx.enforce now no longer deletes minSize for maxSize
  • fixes a bug where splitChunks cause cacheGroups to be incorrectly merged when using the same name
    • now conditions are considered per cacheGroup
    • the correct cache group comment is displayed in stats
  • fixes a bug which causes providedExports not to be updated on rebuilds when using export * from
Commits

The new version differs by 12 commits.

  • f47bf8b 4.27.0
  • a67ffcd Merge pull request #8452 from webpack/feature/resolveWithOptions
  • 96f625c Merge pull request #8457 from webpack/bugfix/rebuild-provided-exports
  • 56feccc convert test case to normal function for node.js 6 support
  • 2f4296e fix a bug which causes incorrect providedExports for cached modules
  • f944002 Merge pull request #8451 from webpack/bugfix/split-chunks
  • 162da1c add getResolve method to loader context
  • 3b46b48 enforce doesn't affect minSize for maxSize
  • 72a8a1f Merge pull request #8440 from Connormiha/oprimize-chunk-can-be-integrated
  • 537d3e4 Cache hasRunstime in chunk
  • e3e8a68 Merge pull request #8405 from xiaoxiaojx/fix-function-plugin-apply
  • 70b9a1b fix parameter missing when plugin type is a funtion

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

[functionality] how about moment-timezone ?

Hi
Thank you for this brilliant plugin, it replaces the old hack we had until now :)

moment-timezone shares with moment a similar problem : the data comes packed with it, it's massive (901 Kb before gzip), and you can't choose just what you need.

There is Luxon, that is using the browser database, but it cant work on some browsers, including IE 11, and anyway it's a massive API change.

Here is what you have in the data :

more node_modules/moment-timezone/data/packed/latest.json
{
        "version": "2018g",
        "zones": [
                "Africa/Abidjan|LMT GMT|g.8 0|01|-2ldXH.Q|48e5",
                "Africa/Accra|LMT GMT +0020|.Q 0 -k|012121212121212121212121212121212121212121212121|-26BbX.8 6tzX.8 MnE 1BAk MnE 1BAk MnE 1BAk MnE 1C0k MnE 1BAk MnE 1BAk MnE 1BAk MnE 1C0k MnE 1BAk MnE 1BAk MnE 1BAk MnE 1C0k MnE 1BAk MnE 1BAk MnE 1BAk MnE 1C0k MnE 1BAk MnE 1BAk MnE 1BAk MnE 1C0k MnE 1BAk MnE 1BAk MnE|41e5",

In my case, instead of all the possible timezones in the world, I just need one, but I would be crazy to code the timezone specific rules, especially given that they can change.
Another use cas would be to have only the America/* timezones for example.

Do you think it's possible to write a plugin that would strip the data, based on an expression ?

An in-range update of webpack is breaking the build 🚨

Version 4.18.0 of webpack was just published.

Branch Build failing 🚨
Dependency webpack
Current Version 4.17.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes v4.18.0

Features

  • Upgrade webassemblyjs dependency
Commits

The new version differs by 12 commits.

  • ee7d948 4.18.0
  • de85978 Merge pull request #7732 from xtuc/chore-bump-webassemblyjs11
  • 4e02cac chore: bump webassemblyjs
  • 52e1630 bump webassemblyjs
  • e0e0061 Merge branch 'master' into chore-bump-webassemblyjs11
  • c9d6ec1 feat: remove wasm-opt
  • 075208d fix: merging
  • 38c3403 Merge remote-tracking branch 'upstream/master' into chore-bump-webassemblyjs11
  • 8214d56 chore: bump webassemblyjs
  • 59114c1 chore: bump webassemblyjs
  • b310b9b feat: remove LEB128 opt
  • f744c4a chore: bump webassemblyjs 1.6.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Default 'en' locale causes error after update to 1.0.6

After update to 1.0.6. got an error in my webpack build pipeline:
Error: MomentLocalesPlugin: Moment.js doesn’t include a locale you specified: en. Check the plugin’s `localesToKeep` option.
I'm passing {localesToKeep:['en']} to the plugin config as before, was working fine pre-update, as the documentation suggests. So it's a regression error, I'd say.

Force localesToKeep to match exactly

There are some locales which names are included in any other locale names, so localesToKeep parameter bring them as well.

For instance:

new MomentLocalesPlugin({
    localesToKeep: ['ca'],
  })

You'll get en-ca and fr-ca, besides ca

Not compatible with yarn2

I get the following error while trying to run my app using yarn version 2.

Error: moment-locales-webpack-plugin tried to access webpack (a peer dependency) but it isn't provided by your application; this makes the require call ambiguous and unsound.

Required package: webpack (via "webpack")
Required by: moment-locales-webpack-plugin@virtual:0ecb949dcbcde61e6cca55949c7becddcb7ebc4a3ef944a62f8dccb560a68ee2d76e2ca7f733ecd2b3ea36a022f329f0cf4d707ef69c07d1d9fbc1e55e943bdd#npm:1.2.0 (via /Users/mbamba/personal/work/monorepo/monorepo/.yarn/$$virtual/moment-locales-webpack-plugin-virtual-a0957a4bde/0/cache/moment-locales-webpack-plugin-npm-1.2.0-7c62d54698-a1613eaa41.zip/node_modules/moment-locales-webpack-plugin/)
Ancestor breaking the chain: @fe/client@workspace:packages/client
Ancestor breaking the chain: @fe/hotel@workspace:packages/hotel

Webpackv5 :: Invalid options object. Ignore Plugin has been initialized using an options object that does not match the API schema.

Executing the MomentLocalesPlugin() in my project that i'm trying to test on Webpack V5 is throwing the following error:

 - options should be one of these:
   object { contextRegExp?, resourceRegExp? } | object { checkResource? }
ValidationError: Invalid options object. Ignore Plugin has been initialized using an options object that does not match the API schema.
    at validate (/Users/req/code/www/project.com/node_modules/webpack/node_modules/schema-utils/dist/validate.js:85:11)
    at new IgnorePlugin (/Users/req/code/www/project.com/node_modules/webpack/lib/IgnorePlugin.js:20:3)
    at new MomentLocalesPlugin (/Users/req/code/www/project.com/node_modules/moment-locales-webpack-plugin/index.js:118:16)
    at Object.<anonymous> (/Users/req/code/www/project.com/build-utils/webpack.common.js:112:9)
    at Module._compile (/Users/req/code/www/project.com/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (/Users/req/code/www/project.com/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/Users/req/code/www/project.com/build-utils/webpack.dev.js:6:22)
    at Module._compile (/Users/req/code/www/project.com/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (/Users/req/code/www/project.com/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at /Users/req/code/www/project.com/webpack.config.js:23:25
    at Array.forEach (<anonymous>)
    at module.exports (/Users/req/code/www/project.com/webpack.config.js:20:13)
    at handleFunction (/Users/req/code/www/project.com/node_modules/webpack-cli/bin/utils/prepareOptions.js:21:13)
    at prepareOptions (/Users/req/code/www/project.com/node_modules/webpack-cli/bin/utils/prepareOptions.js:9:5)
    at requireConfig (/Users/req/code/www/project.com/node_modules/webpack-cli/bin/utils/convert-argv.js:117:14)
    at /Users/req/code/www/project.com/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
    at Array.forEach (<anonymous>)
    at module.exports (/Users/req/code/www/project.com/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
    at /Users/req/code/www/project.com/node_modules/webpack-cli/bin/cli.js:71:45
    at Object.parse (/Users/req/code/www/project.com/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
    at /Users/req/code/www/project.com/node_modules/webpack-cli/bin/cli.js:49:8
    at Object.<anonymous> (/Users/req/code/www/project.com/node_modules/webpack-cli/bin/cli.js:366:3)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18) 

Where this get's really silly, webpack updated their documentation on how to fix this issue, and it pretty cleanly translates to this package:

webpack/webpack.js.org@9dc398b
https://webpack.js.org/plugins/ignore-plugin/

Occurs on https://github.com/iamakulov/moment-locales-webpack-plugin/blob/master/index.js#L118

Webpack deprecation warning DEP_WEBPACK_DEPRECATION_ARRAY_TO_SET

There is a Webpack deprecation warning DEP_WEBPACK_DEPRECATION_ARRAY_TO_SET:

(node:15570) [DEP_WEBPACK_DEPRECATION_ARRAY_TO_SET] DeprecationWarning: Compilation.modules was changed from Array to Set (using Array method 'map' is deprecated)

It can be fixed by small change in utils.js:

- const modulePaths = stats.compilation.modules
+ const modulePaths = Array.from(stats.compilation.modules)

But I think it will require a major version update.

An in-range update of webpack is breaking the build 🚨

The devDependency webpack was updated from 4.35.3 to 4.36.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v4.36.0

Features

  • SourceMapDevToolPlugin append option now supports the default placeholders in addition to [url]
  • Arrays in resolve and parser options (Rule and Loader API) support backreferences with "..." when overriding options.
Commits

The new version differs by 42 commits.

  • 95d21bb 4.36.0
  • aa1216c Merge pull request #9422 from webpack/feature/dot-dot-dot-merge
  • b3ec775 improve merging of resolve and parsing options
  • 53a5ae2 Merge pull request #9419 from vankop/remove-valid-jsdoc-rule
  • ab75240 Merge pull request #9413 from webpack/dependabot/npm_and_yarn/ajv-6.10.2
  • 0bdabf4 Merge pull request #9418 from webpack/dependabot/npm_and_yarn/eslint-plugin-jsdoc-15.5.2
  • f207cdc remove valid jsdoc rule in favour of eslint-plugin-jsdoc
  • 31333a6 chore(deps-dev): bump eslint-plugin-jsdoc from 15.3.9 to 15.5.2
  • 036adf0 Merge pull request #9417 from webpack/dependabot/npm_and_yarn/eslint-plugin-jest-22.8.0
  • 37d4480 Merge pull request #9411 from webpack/dependabot/npm_and_yarn/simple-git-1.121.0
  • ce2a183 chore(deps-dev): bump eslint-plugin-jest from 22.7.2 to 22.8.0
  • 0beeb7e Merge pull request #9391 from vankop/create-hash-typescript
  • bf1a24a #9391 resolve super call discussion
  • bd7d95b #9391 resolve discussions, AbstractMethodError
  • 4190638 chore(deps): bump ajv from 6.10.1 to 6.10.2

There are 42 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.