-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Expose just scripts for chunks #769
Comments
Hey @LorenDorez 👋, |
Sound right. It's time to "DRY" this package a little and provide more fine-grained functionality. |
So I have a similar need but instead of it being to exclude entrypoints I want to be able to specify which chunk I want to generate script tags/elements or assets from. I feel like we could solve both of these issues by adding the ability to specify which chunks you want to generate elements/tags for. So for example, within the ChunkExtractor I want to be able to specify multiple entrypoints as below: const extractor = new ChunkExtractor({
statsFile: statsFilePath,
entrypoints: ["polyfill", "foobar"],
}); The way that we use polyfills in our app is based on feature detection on the browser. So I don't want to generate script elements for the polyfill assets but I want to make sure that the chunk information is generated. We then extract the polyfill asset urls and pass those onto the frontend. If we detect that polyfills are necessary, we create the script elements at runtime and load the polyfills before running the rest of the application. This used to be possible using something like: const baseSrcs = extractor.stats.entrypoints[initialEntrypoint].assets;
const polyfillSrcs: string[] = extractor.stats.entrypoints.polyfill.assets;
return polyfillSrcs.filter(src => !baseSrcs.includes(src)); But this is no longer the case due to #735. So my suggestion is that we allow a filter of sorts whenever calling getScriptElements, getMainAssets and others that will only filter out anything that you don't want to include. Example: extractor.getScriptElements(extraprops, chunksIWant);
extractor.getMainAssets("script", chunksIWant); I have a prototype written locally that I can polish and put into a PR if interested? My only concern is the method signatures. Currently extractor.getScriptElements({}, ["foobar"]);
extractor.getMainAssets(null, ["foobar"]); My personal opinion is that the arguments are converted into a single object. getScriptElements({ extraProps: {}, filteredChunks: []}) {
...
} And so usage becomes like so, allowing you to specify which options you want: extractor.getScriptElements({ filteredChunks: ["foobar"] }); The only problem with that is that it introduces a breaking change requiring a major version bump. Curious your thoughts on it? I'm open to writing it myself and have the bandwidth to do so if we decide on a direction here. Especially since it's something that we need to be able to upgrade. |
It might be a better idea to create a more complex API for more complex cases. Not extend existing. |
Fair enough, I'll start exploring that and put up a PR so that we can discuss it further. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
🚀 Feature Proposal
I would like a method on the extract to get the scripts minus the entry points.
Motivation
Since im doing SSR through ReactJS.net i already have the entry scripts load on the page. I just need the chunks.
Example
Current
Suggested quick mockup
Pitch
This will allow for better integration with a Popular SSR library for react called ReactJS.net
The text was updated successfully, but these errors were encountered: