{"action":"created","issue":{"url":"https://api.github.com/repos/moment/moment/issues/2373","repository_url":"https://api.github.com/repos/moment/moment","labels_url":"https://api.github.com/repos/moment/moment/issues/2373/labels{/name}","comments_url":"https://api.github.com/repos/moment/moment/issues/2373/comments","events_url":"https://api.github.com/repos/moment/moment/issues/2373/events","html_url":"https://github.com/moment/moment/issues/2373","id":75955380,"number":2373,"title":"Modularize moment.js, make the core as light as possible","user":{"login":"srcspider","id":338910,"avatar_url":"https://avatars1.githubusercontent.com/u/338910?v=3","gravatar_id":"","url":"https://api.github.com/users/srcspider","html_url":"https://github.com/srcspider","followers_url":"https://api.github.com/users/srcspider/followers","following_url":"https://api.github.com/users/srcspider/following{/other_user}","gists_url":"https://api.github.com/users/srcspider/gists{/gist_id}","starred_url":"https://api.github.com/users/srcspider/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srcspider/subscriptions","organizations_url":"https://api.github.com/users/srcspider/orgs","repos_url":"https://api.github.com/users/srcspider/repos","events_url":"https://api.github.com/users/srcspider/events{/privacy}","received_events_url":"https://api.github.com/users/srcspider/received_events","type":"User","site_admin":false},"labels":[{"id":168358,"url":"https://api.github.com/repos/moment/moment/labels/Enhancement","name":"Enhancement","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/moment/moment/milestones/15","html_url":"https://github.com/moment/moment/milestone/15","labels_url":"https://api.github.com/repos/moment/moment/milestones/15/labels","id":555799,"number":15,"title":"3.0","description":"Next major","creator":{"login":"ichernev","id":757060,"avatar_url":"https://avatars2.githubusercontent.com/u/757060?v=3","gravatar_id":"","url":"https://api.github.com/users/ichernev","html_url":"https://github.com/ichernev","followers_url":"https://api.github.com/users/ichernev/followers","following_url":"https://api.github.com/users/ichernev/following{/other_user}","gists_url":"https://api.github.com/users/ichernev/gists{/gist_id}","starred_url":"https://api.github.com/users/ichernev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ichernev/subscriptions","organizations_url":"https://api.github.com/users/ichernev/orgs","repos_url":"https://api.github.com/users/ichernev/repos","events_url":"https://api.github.com/users/ichernev/events{/privacy}","received_events_url":"https://api.github.com/users/ichernev/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":2,"state":"open","created_at":"2014-02-01T20:30:00Z","updated_at":"2017-03-05T03:56:47Z","due_on":null,"closed_at":null},"comments":70,"created_at":"2015-05-13T11:38:18Z","updated_at":"2017-03-10T23:30:07Z","closed_at":null,"body":"I remember when moment was a \"lightweight\" library, right now at 12kb (gziped no less) for, what it's in most cases, just very very simple date manipulation.\n\nA simple solution to this problem would be to modularize momentjs so at least for environments like browerify, webpack and such a minimal version can be obtained.\n\neg.\n\nRegular usage can stay the same,\n\n``` js\n// get everything under the sun\nvar moment = require('moment');\n```\n\nModular usage could look like this,\n\n``` js\n// get core, the core does nothing, no validation, no nothing\n// it would only define a internal storage structure and the bare minimum\n// methods for getting values out of it: day, month, year, etc (no \"format\" \n// functions or \"fromNow\" since you might not even want to use them)\nvar moment = require('moment/core');\n\n// add plugins for all the stuff you need, if you ever want ALL of them you \n// just include the directory instead (node/browserify/webpack will pick up\n// a index.js inside it that would have all the things)\nmoment.plugin([\n\n    // if you know this is all the parsers you need this is all you add\n    require('moment/plugins/parser/yyyy-mm-dd-time'),\n    require('moment/plugins/parser/unixtime'),\n\n    require('moment/plugins/validator/yyyy-mm-dd-time'),\n    // if we don't use unixtime locally, only on server we dont care for that\n    // when it comes to validation\n\n    require('moment/plugins/fromNow'),\n    require('moment/plugins/toUnixTime'),\n\n    // with a modular structure we can add 3rd party stuff really easily\n    require('moment-phpstyle-format'),\n    require('moment-chained-functions-format')\n\n]);\n\n// lock in the configuration so that calling plugin method throw and exception\n// this would be irreversible but you can get a unlocked version by calling copy\n// this will force people to get a \"copy\" of the configuration before doing \n// anything stupid -- or help them find the mistake if they add it later\nmoment.lock();\n\n// you now just include this file where you need it\nmodule.exports = moment;\n```\n\nLet's pretend the above is in something like `lib/moment` and represents your default boilerplate configuration for it. Obviously you may eventually encounter situations where you need more advanced functions. If we add to the default boilerplate we unfortunately add to every other context that doesn't need it. This is a big bummer if we're trying to keep client size down with things like webpack code splitting. \n\n**However**, so long as the modular system is capable of being extending any time there's no problem whatsoeve. Ideally, to avoid subtle race condition bugs, we should be able to get a new \"advanced\" version as a separate instance:\n\n``` js\n// load boilerplate we defined previously\n// we request a copy of the instance so no funny business happens\nvar moment = require('lib/moment').copy(); \n\n// we can also create a separate boilerplate if we re-use this a lot\nmoment.plugin(require('expensive-internationalization-timezone-nonsense'));\nmoment.lock(); // lock the new copy just in case its passed around\n\n// moment instances should be able to do a quick copy between instances\n// to ensure functionality, ie. moment(createdAt) could just swap plugin pointers\n```\n\nNow only the module that actually uses that feature pays the cost. If you use moment in 100 places and only 1 actually needs internationalization just that one place will ever pay for it. This applies to all functions, all the core needs to do is store a plain date object and some getters. Is everything you do just pass unix time from the server? you can just have unixtime parser. Do you only ever validate dates on the server? you can skip on any and all validation, etc. \n\nIt's effectively as light as you building your own specialized helpers. And much like projects like gulp, postcss and so on the community can contribute easily to it though easily maintainable chunks.\n\nAnd in this way, momentjs can, _once again_, be called \"[lightweight javascript date library](https://web.archive.org/web/20111214102140/http://momentjs.com/)\".\n"},"comment":{"url":"https://api.github.com/repos/moment/moment/issues/comments/285813745","html_url":"https://github.com/moment/moment/issues/2373#issuecomment-285813745","issue_url":"https://api.github.com/repos/moment/moment/issues/2373","id":285813745,"user":{"login":"pke","id":164625,"avatar_url":"https://avatars3.githubusercontent.com/u/164625?v=3","gravatar_id":"","url":"https://api.github.com/users/pke","html_url":"https://github.com/pke","followers_url":"https://api.github.com/users/pke/followers","following_url":"https://api.github.com/users/pke/following{/other_user}","gists_url":"https://api.github.com/users/pke/gists{/gist_id}","starred_url":"https://api.github.com/users/pke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pke/subscriptions","organizations_url":"https://api.github.com/users/pke/orgs","repos_url":"https://api.github.com/users/pke/repos","events_url":"https://api.github.com/users/pke/events{/privacy}","received_events_url":"https://api.github.com/users/pke/received_events","type":"User","site_admin":false},"created_at":"2017-03-10T23:30:07Z","updated_at":"2017-03-10T23:30:07Z","body":"momenjs even without the locales still comes in at 140kb atm. For simple date formatting, that's way to much. Switching to something else now."}}
{"actor":{"display_login":"pke"}}