Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Smaller bundle size #117

Merged
merged 6 commits into from
Feb 22, 2023
Merged

Smaller bundle size #117

merged 6 commits into from
Feb 22, 2023

Conversation

hmuurine
Copy link
Collaborator

Summary

This PR makes the build bundle sizes smaller. There were a couple of issues that increased the size of both the final implementation player.js build size and the size of the library JS packages. The main issue was that the library code was included twice in the JS packages.

Bundle size of library and ui-library

The library builds bundled all their external and internal dependencies within the dist/*.js package.

  • Could be excluded by adding externals section in library Webpack builds
  • The only one who needs to import and bundle these external dependencies is the final implementation application
  • dist/*.js size reductions:
    • library 128kB -> 118kB
    • ui-library 217kB -> 67kB (previously bundled also library within the JS in addition to the external dependencies)

Bundle size of player.js

The build pipeline bundled two versions of the library code into the final package. This could be seen by opening and investigating the final player.js, which had two versions of the library code.

  • Both the local build and the NPM version of library were added to the bundle
  • Local build was added because the implementation/EpicGames linked locally to it via npm link ../library
  • NPM version was added because ui-library ended up using the NPM version when the final build was made. Reasons:
    • Running npm ci after npm link overwrites the link
    • Also running first npm link ../library in ui-library, but then running npm link ../../ui-library in EpicGames resets the linking in ui-library. The links need to be set up in opposite order if both need to be preserved: first in EpicGames, then in ui-library.
  • Fixing this has the greatest effect: player.js 347k -> 220kB

Exporting ESM modules

The library modules were exported as umd modules, which isn't tree-shakeable.

  • Added esm module build in addition to umd
  • esm module is provided in package.json module and umd in package.json main. Dependency users are automatically able to choose which ones to use
  • The final build was able to shake something out of the code, but not much: player.js 220kB -> 218kB
    • Maybe expected since the sample application uses pretty much all the functionality that is available through the library

"types": "types/pixelstreamingfrontend.d.ts",
"sideEffects": false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just promises that our library does not do any side effects when the library is imported. All the effects are done through direct calls, not just by importing. This allows the tree shaking mechanisms to drop any library code that isn't referenced.

"jss": "^10.9.2",
"jss-plugin-camel-case": "^10.9.2",
"jss-plugin-global": "^10.9.2"
},
"peerDependencies": {
"@epicgames-ps/lib-pixelstreamingfrontend-ue5.2": "0.1.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require library as a peer dependency provided through the implementation application dependencies, not as a transitive dependency through ui-library. This might prevent us from having two distinct versions as dependencies in the final build, one from direct dependency, one through ui-lib.

Copy link
Contributor

@lukehb lukehb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Landing.

@lukehb lukehb merged commit 6282965 into EpicGames:master Feb 22, 2023
lukehb added a commit that referenced this pull request Feb 23, 2023
Bring smaller bundle size fix to 5.2 (#117)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants