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

Using only specific loader type without importing whole spinner #23

Closed
archansel opened this issue Dec 28, 2017 · 11 comments
Closed

Using only specific loader type without importing whole spinner #23

archansel opened this issue Dec 28, 2017 · 11 comments

Comments

@archansel
Copy link

Hi, is there any way to load only one specific loader without the whole spinner being bundled. Something like what lodash did, for example:

import BarLoader from 'react-spinners/bar-loader';
@ThomasBem
Copy link

Would also be interested in this! Currently react-spinners is 9% of our small apps total bundle size.

Love the spinners though! RingLoader is awesome :)

@davidhu2000
Copy link
Owner

davidhu2000 commented Apr 22, 2018

@archansel @ThomasBem, I ran a quick test, looks you like can import just one.

import BarLoader from 'react-spinners/dist/spinners/BarLoader';

Trying to see how I can remove the /dist/spinners part`.

import { BarLoader } from 'react-spinners';: 51.23 KB
import BarLoader from 'react-spinners/dist/spinners/BarLoader';: 47.44 KB

The file sizes are the size after gzip. I used create-react-app and just added the loader and build the production build.

Can you guys give that a try and see if the bundle size is reduced?

@Dman757
Copy link

Dman757 commented Jul 20, 2018

@davidhu2000 Figured I would chime in to confirm this worked on my end. I used source-map-explorer for a quick test. https://www.npmjs.com/package/source-map-explorer

I'm only using BarLoader and PulseLoader
import PulseLoader from 'react-spinners/dist/spinners/PulseLoader';
import BarLoader from 'react-spinners/dist/spinners/BarLoader';

Before
Before

After
After

GuillaumeCisco added a commit to GuillaumeCisco/react-spinners that referenced this issue Jul 31, 2018
@davidhu2000
Copy link
Owner

@GuillaumeCisco Just merged in your PR, but looks like single loader import isn't working.

I'm looking at possible solutions, not sure why. I had to deprecate 0.4.0. We need to push out a patch for this.

@davidhu2000
Copy link
Owner

I just published a patch 0.4.1 that removes the single loader import from the readme. So hopefully very few people uses 0.4.0.

@davidhu2000
Copy link
Owner

looks like the issue is you need to import BarLoader from 'react-spinners/dist/BarLoader';

@GuillaumeCisco
Copy link
Contributor

GuillaumeCisco commented Aug 11, 2018 via email

@davidhu2000
Copy link
Owner

davidhu2000 commented Aug 11, 2018

This is fixed in >= 0.4.2

@ThomasBem
Copy link

We came back to our app recently where we use one of your spinners as our main loading animation. Updated to 0.4.3 and changed the import like you said and now our bundle size dropped by 50KB.

Just wanted to say thanks! 👍

@kifirkin
Copy link

kifirkin commented Mar 1, 2019

@davidhu2000 Can't use this import method with typescript. I've got error: Could not find a declaration file for module 'react-spinners/GridLoader'.

@davidhu2000
Copy link
Owner

hmm, @alexmironof can you open a new issue? This feels like a different issue that the current issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants