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

Migrate from Terser and Babel to SWC #6920

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Conversation

marklundin
Copy link
Member

@marklundin marklundin commented Sep 6, 2024

This PR replaces Babel + Terser with SWC which improves the build time of each target.

The same ES5 targets are used for UMD build outputs.

With Terser/Babel ~ 1m40s

created build/playcanvas.js in 9.9s
created build/playcanvas in 6.2s
created build/playcanvas.mjs in 1.3s
created build/playcanvas.dbg.js in 9.8s
created build/playcanvas.dbg in 6s
created build/playcanvas.dbg.mjs in 1.8s
created build/playcanvas.prf.js in 9.4s
created build/playcanvas.prf in 6s
created build/playcanvas.prf.mjs in 1.2s
created build/playcanvas.min.js in 7.5s
created build/playcanvas.min.mjs in 6.4s

With SWC ~ 51s

created build/playcanvas.js in 3.6s
created build/playcanvas in 2.6s
created build/playcanvas.mjs in 1.3s
created build/playcanvas.dbg.js in 3.8s
created build/playcanvas.dbg in 2.6s
created build/playcanvas.dbg.mjs in 1.6s
created build/playcanvas.prf.js in 3.2s
created build/playcanvas.prf in 2.6s
created build/playcanvas.prf.mjs in 1.2s
created build/playcanvas.min.js in 1.9s
created build/playcanvas.min.mjs in 1.4s

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@LeXXik
Copy link
Contributor

LeXXik commented Sep 6, 2024

Any change to sizes?

@Maksims
Copy link
Collaborator

Maksims commented Sep 6, 2024

Also is there a difference in ECMA compliance, if there is a difference between ES5 versio s, and what it results in?

@marklundin
Copy link
Member Author

marklundin commented Sep 6, 2024 via email

@LeXXik
Copy link
Contributor

LeXXik commented Sep 9, 2024

If it is not possible to bring the build size to what terser is capable of, then we can consider to use this for a debug build, as it is usually the one that takes the most of the time during development and its size is of less importance.

@marklundin
Copy link
Member Author

Below are the file sizes. Will continue investigating

Build Output SWC Babel/Terser
playcanvas.d.ts 1.7MiB 1.7MiB
playcanvas.dbg.js 16MiB 18MiB
playcanvas.dbg.mjs 13MiB 16MiB
playcanvas.js 2.8MiB 2.9MiB
playcanvas.min.js 1.6MiB 1.7MiB
playcanvas.min.mjs 1.6MiB 1.6MiB
playcanvas.mjs 2.7MiB 2.5MiB
playcanvas.prf.js 2.8MiB 2.9MiB
playcanvas.prf.mjs 2.7MiB 2.5MiB

package.json Outdated
"@rollup/plugin-terser": "^0.4.4",
"@rollup/pluginutils": "^5.1.0",
"c8": "^10.1.2",
"@swc/core": "^1.7.23",
"c8": "^9.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

How come c8 was bumped down in this PR?

@willeastcott
Copy link
Contributor

willeastcott commented Dec 23, 2024

The wins from this look extremely compelling. I'd be supportive of switching.

- Added "peer": true to several existing dependencies to indicate peer dependencies.
- Introduced new modules: jackspeak (v3.4.3) and package-json-from-dist (v1.0.1) with their respective details.
- Added path-scurry (v1.11.1) and its dependency lru-cache (v10.4.3) with funding information.

These changes enhance dependency management and ensure compatibility with peer dependencies.
- Eliminated the babel-parser dependency from the ESLint configuration file.
- Updated the parser options to ensure compatibility with the existing setup.

These changes streamline the ESLint configuration and reduce unnecessary dependencies.
- Changed the import name of the SWC plugin from 'swc' to 'swcPlugin' for clarity.
- Updated all instances in the buildTarget function to use the new import name.

These changes improve code readability and maintainability.
- Removed several unused Babel-related dependencies from package.json and package-lock.json to streamline the project.
- Updated the package-lock.json to reflect the removal of these dependencies and added optional flags where applicable.
- Enhanced dependency management by ensuring that only necessary modules are retained, improving overall project maintainability.
… rollup-spaces-to-tabs.mjs

- Deleted the rollup-script-target.mjs file, streamlining the build process.
- Updated swcOptions to ensure comments are preserved in the output when not minifying.
- Clarified documentation in rollup-spaces-to-tabs.mjs regarding the plugin's functionality.

These changes enhance code maintainability and improve the clarity of the build configuration.
…ting

- Adjusted the formatting of the `pure_funcs` array in the `swcOptions` function to ensure consistency.
- This change enhances code readability and maintains the existing functionality of the build configuration.
- Upgraded the version of the 'playcanvas' package from 2.3.0-dev to 2.4.0-dev.
- Updated several dependencies, including '@webgpu/types' from ^0.1.40 to ^0.1.52, and '@playcanvas/eslint-config' from ^2.0.2 to ^2.0.8.
- Removed multiple unused rebuild package lock
…s for Rollup. See vitejs/vite#15532

- Added optional dependencies for various Rollup packages, including support for multiple platforms (Linux, Darwin, FreeBSD, Windows).
- Updated package-lock.json to reflect the addition of these optional dependencies and their respective versions.
- This change enhances cross-platform compatibility and ensures that the build process can leverage the appropriate Rollup binaries as needed.
…lated dependencies

- Upgraded @swc/core to version 1.10.1 and updated its dependencies across various platforms.
- Removed the optional dependency for @rollup/rollup-linux-x64-gnu.
- Updated @swc/types to version 0.1.17 for improved compatibility.
- These changes enhance the project's build capabilities and ensure better support for the latest SWC features.
@marklundin
Copy link
Member Author

marklundin commented Dec 24, 2024

Comparison of Existing Build System vs SWC

File Existing Gzip Size Existing Build Time SWC Gzip Size SWC Build Time
playcanvas.dbg.js 4.0MiB 10.7s 3.9MiB 4.9s
playcanvas.dbg.mjs 3.2MiB 2.5s 3.2MiB 2.2s
playcanvas.js 588KiB 10.6s 555KiB 3.4s
playcanvas.min.js 431KiB 7.0s 412KiB 1.9s
playcanvas.min.mjs 416KiB 6.5s 419KiB 1.8s
playcanvas.mjs 536KiB 1.4s 551KiB 1.4s
playcanvas.prf.js 589KiB 8.8s 556KiB 5.1s
playcanvas.prf.mjs 537KiB 1.4s 552KiB 2.0s

Observations

  • Build Times: SWC achieves faster build times across all most types
  • Gzip Sizes: SWC gzip sizes are generally comparable or slightly smaller, except for playcanvas.min.mjs and playcanvas.mjs.

@willeastcott willeastcott changed the title Replaces Terser/Babel. Improves Build Time Migrate from Terser and Babel to SWC Dec 26, 2024
Comment on lines 17 to 19
parserOptions: {
requireConfigFile: false
},
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't need the Babel parser any more, can we also drop parserOptions? I think we only added this for Babel.

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

Successfully merging this pull request may close these issues.

4 participants