Use src/index as browser entry point #1106
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
dependenciescategory so they are installed for users of this package (scratch-gui for example)Reason for Changes
This saves file space by excluding extra webpack boilerplate, excluding extra copies of dependencies and may allow for deeper optimizations.
As is, scratch-* packages build in their dependencies. Three such packages build in
text-encoding: scratch-vm, scratch-storage, and scratch-gui. These three copies are each ~500KB of source before minification and compression. Importantly they are also duplicate execution paths, that build up 3 copies of the same runtime memory structures and 3 copies of compiled functions. There are two copies of scratch-svg-renderer's 1.8MB source depended on by scratch-render and scratch-gui.Removing these duplicate copies brings the scratch-gui lib.min.js file size from (webpack 4's) 9.2MB (3.6 gzipped) to 7.1MB (2.8 gzipped). (Additionally with #1105 this further drops to 5.2MB (1.4 gzipped). The music sample js with webpack-4 branch's arraybuffer-loader is 2.0MB (1.4 gzipped))
With the webpack-4 branch this reduces runtime memory usage on a Samsung Chromebook Plus from 28MB (develop) to 21MB (webpack-4) to 18MB.
caveats
The main caveat for this change is that some building details would need repeating in some of the packages depending on other scratch packages like scratch-vm and scratch-gui. Packages with their module rules configurations are not automatically included in builds consuming that package. scratch-render for instance uses
ify-loaderon its linebreak andgrapheme-breakerdependencies. scratch-vm and scratch-gui need to support handling this.There are some ways that this could be resolved in the dependencies. Parts that need this extra handling could be prebuilt. Instead of building the entire package for use in later browser builds, the parts with webpack configuration details could be prebuilt and depended on by the package's source.
Some babel details can be handled by compiling to another build folder with modules individually compiled using the
babelcli tool.Probably the easiest option would be to inline the loader configuration details. Many binary files in the scratch packages have their loader stated in the
requirerequest. This could be extended to other dependencies likelinebreakin scratch-vm to resolve this.merging
A second minor caveat is this PR should be merged with its sibling PRs in each package or from top down, starting at scratch-gui. Directly related to build configuration packages using other scratch packages needed to handle cases building where the consumed packages have build details that are not already handled.