-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Webpack bundle.js size #874
Comments
Hi! Have you tries deep importing the component directly, e.g.
```
import SingleDatePicker from 'react-dates/lib/components/SingleDatePicker';
```
The index for `react-dates` includes all of the exports which might be
contributing.
…On Fri, Dec 1, 2017, 10:05 AM Julio Ojeda ***@***.***> wrote:
I am using react-dates in my app. I am trying to reduce the size of my
bundle.js generated by webpack. I used the "webpack-bundle-analyzer" and I
noticed React-dates module is including components I am not using in my app.
I only imported SingleDatePicker and RangeDatePicker but I am getting all
the components in bundle. I tried to use the webpack.IgnorePlugin but I was
not able to get this done.
To import I used
import { SingleDatePicker } from 'react-dates';
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#874>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUdtUU_JLBDdYLNWOsGaBsfj5kKYDwDks5s8D_tgaJpZM4QytRB>
.
|
Hi @majapw I tried but still it's kind of big. It's around 350kb. My bundle has other files such as DarPicker.js, CalendarMonth.js . I think they are used by SingleDataPicker that is why webpack is adding them. Correct me if I am wrong please. |
Perhaps this is the only thing adding moment? Moment can be large in webpack because i believe it grabs up all locales by default. |
SingleDatePicker does use a number of other components under the hood... it's a fairly complex component. moment is also quite a big package. @lencioni might have some more thoughts on optimization. |
Indeed, Moment can easily blow up your bundle size, especially if you aren't being really careful about what it brings in. I think they have a plan to make it easier to do the right thing, but I'm not sure if it has landed yet. In #791 we added an /esm build that you will want to hook up via a webpack alias, if you are on a new enough version of webpack (2+ IIRC). https://webpack.js.org/configuration/resolve/#resolve-alias That should give you smaller modules for react-dates and allow tree shaking to actually work for the react-dates code. Beyond that, I think it would be impactful to have a way to be able to code split parts of react-dates, so you only bring in the parts that are needed for the initial render for your parent bundle, and then async load the rest as needed. I opened an issue for this here: #839 However, I am expecting a baby at any moment so it is unlikely that I'll be able to do any work on that any time soon. If you are looking for a way to contribute and help solve this problem for everyone, that would be a great issue to dig into. |
@lencioni could you provide more details on how to use /esm with webpack alias? |
@jeznag I think you would need to add something like this to your webpack's 'react-dates/lib': 'react-dates/esm', More info: https://webpack.js.org/configuration/resolve/#resolve-alias |
Hi @lencioni I do what you suggest about alias and get same result about big size on bundle on |
@jorgecuesta I've worked around your exact issue. The problem is I solved this by simply aliasing moment in my webpack config to the later version. This could cause issues with So something like this would probably help you
|
Hmm, |
I'd try running |
Alright, @ljharb @majapw, I checked out an old commit and dug into what caused my issue a bit more. At the time I had this issue I had moment installed as
And from there Yarn installed a duplicate moment within Not sure if this helps @jorgecuesta... :) |
Thanks guys @majapw @ljharb and @jbfm to take time to see this.
I use Yarn all the time, maybe I need install same I will try using |
Thanks for the tip. Using the alias seems to save 2kb gzipped. Hopefully further size savings will be available down the line. Particularly keen to reduce size of moment. |
Running into the same issue while just importing the util Importing it like I'm now looking at another app, where I use the I will try the suggested deep importing |
for moment optimizations try this plugin to strip redundant locales https://github.com/iamakulov/moment-locales-webpack-plugin |
@mjmonline you can pretty much achieve the same using webpacks Context Replacement Plugin
|
I built a tool to help you analyze webpack bundles for size regressions, and report them directly to GitHub PRs. It's free for open source, so it might be worth checking out and helpful in this scenario. |
I think another optimisation that would greatly reduce the bundle size for Webpack users is to use the At the moment, without it being set, even when using Additionally I think it would also make sense to declare the |
I am using react-dates in my app. I am trying to reduce the size of my bundle.js generated by webpack. I used the "webpack-bundle-analyzer" and I noticed React-dates module is including components I am not using in my app.
I only imported SingleDatePicker and RangeDatePicker but I am getting all the components in bundle. I tried to use the webpack.IgnorePlugin but I was not able to get this done.
To import I used
import { SingleDatePicker } from 'react-dates';
The text was updated successfully, but these errors were encountered: