-
Notifications
You must be signed in to change notification settings - Fork 4
Replace Babel with SWC for transpilation #745
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
815ee00
Initial plan
Copilot 5082aa7
Replace Babel with SWC for faster builds
Copilot 3b5b439
Fix ESLint configuration for SWC migration
Copilot 0920935
Documentation: Add migration summary
Copilot 1eac4b2
Merge branch 'main' into copilot/replace-babel-with-swc
supervoidcoder 3cc0ee1
Fix module system: Use ES6 modules instead of CommonJS
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,14 @@ | ||
| module.exports = { | ||
| extends: ['scratch', 'scratch/node', 'scratch/es6'] | ||
| extends: ['scratch', 'scratch/node', 'scratch/es6'], | ||
| parser: '@babel/eslint-parser', | ||
| parserOptions: { | ||
| requireConfigFile: false, | ||
| sourceType: 'module', | ||
| ecmaFeatures: { | ||
| jsx: true | ||
| }, | ||
| babelOptions: { | ||
| presets: ['@babel/preset-react'] | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/swcrc", | ||
| "jsc": { | ||
| "parser": { | ||
| "syntax": "ecmascript", | ||
| "jsx": true, | ||
| "dynamicImport": true, | ||
| "decorators": false | ||
| }, | ||
| "transform": { | ||
| "react": { | ||
| "runtime": "classic", | ||
| "pragma": "React.createElement", | ||
| "pragmaFrag": "React.Fragment", | ||
| "throwIfNamespace": true, | ||
| "development": false, | ||
| "useBuiltins": false | ||
| } | ||
| } | ||
| }, | ||
| "module": { | ||
| "type": "es6" | ||
| }, | ||
| "env": { | ||
| "targets": { | ||
| "chrome": "102", | ||
| "edge": "18", | ||
| "firefox": "68", | ||
| "safari": "12", | ||
| "ios": "12" | ||
| }, | ||
| "mode": "usage", | ||
| "coreJs": "2.5.7" | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: OmniBlocks/scratch-gui
Length of output: 100
🏁 Script executed:
# Check the .swcrc file to see the full configuration cat -n .swcrcRepository: OmniBlocks/scratch-gui
Length of output: 929
🌐 Web query:
SWC .swcrc env.coreJs supported versions format documentation💡 Result:
In SWC
.swcrc,env.coreJsis:Type/format: a string (not a number). Example:
{ "env": { "mode": "entry", "coreJs": "3.22" } }(swc.rs)
What values are supported: any
core-jsversion supported by SWC; SWC recommends specifying at least the minor version (e.g."3.22"). If you set"3", SWC interprets it as"3.0", which may miss newer polyfills. (swc.rs)When it applies: only when
env.modeis"usage"or"entry"(similar to Babel’suseBuiltIns). (swc.rs)Official docs page: SWC “Supported Browsers” configuration docs (includes
env.coreJs). (swc.rs)Citations:
🏁 Script executed:
Repository: OmniBlocks/scratch-gui
Length of output: 284
🏁 Script executed:
Repository: OmniBlocks/scratch-gui
Length of output: 73
🌐 Web query:
SWC core-js 2.5.7 support compatibility legacy💡 Result:
SWC’s built-in polyfill injection (
env.mode: "entry"/"usage"+env.coreJs) is designed to work with moderncore-jslines (the SWC docs/examples showcoreJs: "3.xx"; core-js docs also document SWC integration withcoreJs: "4.0"), and there’s no documented/official support for targeting core-js 2.5.7 via SWC’senv.coreJsoption. [1], [2]What that means for core-js@2.5.7 (legacy):
env.coreJsmechanism—use manual polyfill entry imports (or a different toolchain) instead. Core-js 2.x explicitly targets very old browsers (IE6+, Android 2.3+, etc.). [3]Practical recommendation: For “legacy but not ancient” (e.g., IE11), move to
core-js@3and set SWCenv.coreJsto a specific minor like"3.22"(as SWC recommends). [1], [4]Sources:
[1] SWC docs – Supported Browsers /
env.coreJsoption https://swc.rs/docs/configuration/supported-browsers[2] core-js docs – SWC integration example (coreJs “4.0”) https://core-js.io/web/docs/usage.html
[3] core-js 2.x npm page (supported engines list) https://www.npmjs.com/package/core-js/v/2.5.6
[4] core-js docs – guidance on core-js 3 vs 4 baseline/legacy support https://core-js.io/v4/docs/engines
Migrate from core-js 2.5.7 to core-js 3.x for proper SWC polyfill injection.
SWC's
env.coreJsmechanism only supports core-js 3+ (with examples showing 3.22+) and 4.0+. Core-js 2.5.7 is legacy and not officially supported, meaning polyfills configured inenv.mode: "usage"will not be properly injected. Updatepackage.jsonto use core-js 3, and set"coreJs": "3.22"(or the appropriate minor version) in.swcrc.🤖 Prompt for AI Agents