Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a plugin to webpack config w/o ejecting #1060

Closed
orditeck opened this issue Nov 18, 2016 · 13 comments
Closed

Add a plugin to webpack config w/o ejecting #1060

orditeck opened this issue Nov 18, 2016 · 13 comments

Comments

@orditeck
Copy link

Is that possible? I'm using moment and it loads all the locales (so moment takes 200kB instead of 50kB in the build), the current fix for more than one year seems to be to exclude the locales via webpack using:

new webpack.ContextReplacementPlugin(/moment[\\\/]locale$/, /^\.\/(en)$/)

I tried to add it manually to /node_modules/react-scripts/config/webpack.config.prod.jsand it works but I can't do that, and I don't want to eject.

@gaearon
Copy link
Contributor

gaearon commented Nov 18, 2016

Maybe it's time for somebody to fork moment and make it Webpack-friendly if they'd rather not fix it? It's really not right that a library requires changes in the config.

And no, we don't intend to allow modifying Webpack configs as this defeats the purpose of this tool. Your best bet would be to bring this up with Moment maintainers (this issue has been affecting people for years) or fork it.

@gaearon gaearon closed this as completed Nov 18, 2016
@orditeck
Copy link
Author

orditeck commented Nov 18, 2016

Ok thanks. It's been pointed out a long time ago to webpack moment maintainers but... well. I'll try to find something else. Thanks!

@gaearon
Copy link
Contributor

gaearon commented Nov 18, 2016

I think it's more of a problem with Moment than with Webpack.

@orditeck
Copy link
Author

orditeck commented Nov 18, 2016

Oh, yeah, my mistake! I meant "momentjs maintainers".

Seems like they're working on it after all! webpack/webpack#3128

@gaearon
Copy link
Contributor

gaearon commented Nov 18, 2016

FWIW if you need something similar to Moment but not suffering from this issue, I recommend date-fns.

@orditeck
Copy link
Author

@gaearon thanks for the suggestion and the time you're taking to reply to me, that's what I'd use as I discovered it while looking for an alternative to moment but the date/timepicker I'm using requires moment. I tried to find one using date-fns but haven't found any, I'll try to search again. Maybe I should create one but I'm not sure it'd fit in the current budget of my client 😊

@thien-do
Copy link
Contributor

@orditeck I used to be in your situation... all I need is a simple date picker and 200 of KB from momentjs come into my app. Now in my simple cases, I just use select boxes..

However, in complex case that a date picker is a must, I suggest you to consider libraries that are not 'react' yet. It is actually quite easy to use any libraries with react, because they are just JS after all.

If you already have jquery, then https://github.com/amsul/pickadate.js might be a good choice since it is not depend on momentjs. I think you can even find one that is not depend on any thing at all.

Ps. of course create a new one for community is always appreciate =))

@ezhlobo
Copy link

ezhlobo commented Nov 19, 2016

@orditeck hi. I forked this repository and added the possibility to modify webpack configs. You can take a look at it here: https://github.com/ezhlobo/react-scripts

@jquense
Copy link
Contributor

jquense commented Apr 26, 2017

@gaearon seems like react-scripts could help protect the user transparently here by adding the context replacement plugin. I generally agree with you that this is moment's problem. However, pragmatically:

  1. Moment is the defacto community standard for a datetime library
  2. This problem has existed for a long time and doesn't look like it's gonna get addressed quickly from moment's end.
  3. dateFns is a great probject, but lacks the years of institutional hardening and i18n robustiness of moment, making it a suboptimal choice for folks doing meaningful datetime/i18n work
  4. The ease of someone doing the wrong thing is almost frictionless and the cost large.
  5. react-scripts could fix this without allowing config changes by adding a special case for moment.

I reallly understand not wanting to have a bunch of special cases for user libraries, However maybe it's worth making an exception for community projects that are used extensively?

@jquense
Copy link
Contributor

jquense commented Apr 26, 2017

@gaearon
Copy link
Contributor

gaearon commented Apr 26, 2017

I’d like to, but how do we distinguish from legit cases if people want to bundle those locales?

@jquense
Copy link
Contributor

jquense commented Apr 27, 2017

I'd suggest that no one ever wants to bundle a 115 locales at once. The Ignore would just prevent them from being bundled automatically (as far as I've seen) when you require moment. You can still import/require from moment/locales/en-GB explicitly in the your app for the locales you want.

@gaearon
Copy link
Contributor

gaearon commented Apr 27, 2017

This seems sensible. Want to send a PR?

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants