-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Selective player imports for decreasing bundle size #311
Comments
You could import the import Player from 'react-player/lib/Player'
import YouTube from 'react-player/lib/players/YouTube'
return <Player activePlayer={YouTube} /> Although you would lose out on the functions that A "proper" solution would need an update to the codebase, but I like the idea. |
I haven't fully vetted this yet (still some failing tests), but I have a proof of concept in this branch. |
I don't dislike your solution, but I wonder if we can achieve the same thing in a less intrusive way. We could move the import Player from 'react-player/lib/Player'
import YouTube from 'react-player/lib/players/YouTube'
return <Player activePlayer={YouTube} />
// Or provide a shortcut like
import YouTubePlayer from 'react-player/youtube' The only thing I think we would miss from |
@BuffaloBuffalo I've pushed my attempt at solving this to the import YouTubePlayer from 'react-player/lib/players/YouTube'
<YouTubePlayer
url={url}
playing
controls
// Any other ReactPlayer props will work here, apart from preload config
/> |
@BuffaloBuffalo any thoughts before I merge it? |
I apologize for not getting back to you sooner -- Yes this exactly fits the bill! |
Added in |
This will happen automatically in 2.0.0 (lazy loading of relevant players), try out the alpha release:
|
I'm using react-player within a larger react app using webpack for bundling. Is there any way to organize the imports in a way to selectively bundle only certain players, so that webpack can properly tree-shake out the unused players? Currently I'm only utilizing the file loading and youtube players, however all the players are bundled into prod build due to the players import in
ReactPlayer
:Essentially what I'm looking for is either a specialized import (similar to what some of the react-router libs recommend):
that may look like
Or an API where the parent component explicitly states the Player types that the given URL could be
I realize this is a niche request since I'm to the point of micro-optimizing third party libraries, but figured I'd ask before digging further into it.
The text was updated successfully, but these errors were encountered: