Closed timrwood closed 9 years ago
I'm also not a fan of the progressive prototype extension but if you import
everything and build up a more complete prototype, nobody can tree-shake away parts they don't use :(
Yeah, I'm not sure how much tree shaking would be possible as moment is mostly just one big Moment class.
It would be weird to say that you need to import "moment/units/months";
in order to allow moment().format('MMMM')
.
If you really want to shake stuff out, it means you're 1) hardcore and 2) willing to fix the es6 build errors saying (can not import file) by commenting out the corresponding Foo.prototype.bar = bar (where bar is imported from deleted file). I think this is fair.
@ichernev, yeah, we can have everything that is currently attaching itself to the prototype export the method instead, and have one file to collect everything and assign it.
// lib/moment/diff.js
export function diff (input, units, asFloat) {
...
}
// lib/moment/prototype.js
import { Moment } from "./constructor";
import { diff } from "./diff";
Moment.prototype.diff = diff;
Yes, that was my suggestion :)
@timrwood that'd be good. And people could build up their own Moment manually if they really wanted a smaller profile?
This is done for the moment prototype in eaa06b71a6db7ebe2c691af71500582c8522aafd.
This is done for the locale prototype in ccb406e.
This is done for the duration prototype as well.
Via @ichernev