Closed jainAdijain closed 6 years ago
Install moment version 2.22.0 (newer versions will work with slight adaptations):
npm i --save moment@2.22.0
Install patch-package and add it to your package.json inside the scripts section:
{
"scripts": {
"prepare": "patch-package"
}
}
Create a file under patches/moment+2.22.0.patch
with the following content:
patch-package
--- a/node_modules/moment/moment.js
+++ b/node_modules/moment/moment.js
@@ -1832,7 +1832,7 @@
module && module.exports) {
try {
oldLocale = globalLocale._abbr;
- var aliasedRequire = require;
+ var aliasedRequire = eval('require');
aliasedRequire('./locale/' + name);
getSetGlobalLocale(oldLocale);
} catch (e) {}
--- a/node_modules/moment/src/lib/locale/locales.js
+++ b/node_modules/moment/src/lib/locale/locales.js
@@ -52,7 +52,7 @@ function loadLocale(name) {
module && module.exports) {
try {
oldLocale = globalLocale._abbr;
- var aliasedRequire = require;
+ var aliasedRequire = eval('require');
aliasedRequire('./locale/' + name);
getSetGlobalLocale(oldLocale);
} catch (e) {}
Run npm run prepare
to apply to patch. It will also be applied automatically by patch-package whenever you npm install
.
This workaround makes sure moment does not implicitly bundle any locales - unless you import specific locales that you are interested in.
Then where should I create the "patches" folder? Sorry the solution is not really clear for me. I dont even understand where did you get the codes for the patch file. And what if I have a newer version of moment.js? So I have to change the patch file name? And also I cant understand the codes for the patch file, its missing some brackets so Im thinking its not complete? Because its still not working for me
I am using angular2-moment in ionic-angular application
In a certain component's module I am using
package.json
"angular2-moment": "^1.7.0",
.html
The source maps generated for this module shows locale which increases the size of the overall vendor.
How to remove this locale?