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

swc: generate sourcemaps #163660

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

swc: generate sourcemaps #163660

wants to merge 1 commit into from

Conversation

milahu
Copy link

@milahu milahu commented Oct 14, 2022

i want to build vscode with swc (#150025)
because swc is 10x faster than tsc

(todo: add a gulp task for this, maybe compile-build-swc)

to enable swc in the compile-build task, im patching build/lib/compilation.js

-createCompile(src, build, true, false)
+createCompile(src, build, true, { swc: true })
patching JS files in Nix buildPhase
    # force building with SWC (10x faster than typescript)
    substituteInPlace build/lib/compilation.js \
      --replace 'createCompile(src, build, true, false)' 'createCompile(src, build, true, { swc: true })'
    # swc: generate sourcemaps for build/lib/nls.js
    # fix: Error: File vs/nls.build.js does not have sourcemaps.
    substituteInPlace build/lib/tsb/transpiler.js \
      --replace 'this._jobs.push(swc.transform' 'options.sourceMaps = true; this._jobs.push(swc.transform'

but then i get

Error: File vs/nls.build.js does not have sourcemaps.
Using gulpfile ~/gulpfile.js
Starting 'compile-build'...
Starting clean-out-build ...
Finished clean-out-build after 10 ms
Starting build-web-node-paths ...
Finished build-web-node-paths after 13 ms
Starting <anonymous> ...
Starting compilation...
'compile-build' errored after 35 s
Error: File vs/nls.build.js does not have sourcemaps.
    at Stream.<anonymous> (/build/source/build/lib/nls.js:59:39)

... because by default, swc does not generate sourcemaps

swc.Options type: swc/node-swc/src/types.ts

with this patch, the compile-build task still fails with

WIP

Error: File vs/nls.mock.js does not have sourcemaps.

todo: options.sourceMaps = "inline"; options.inlineSourcesContent = true;

TODO enable sourcemaps only on demand

maybe pass this option as transpileOnly = { swc: { sourceMaps: true } }

function createCompile(src: string, build: boolean, emitError: boolean, transpileOnly: boolean | { swc: boolean }) {

with

-transpileOnly: boolean | { swc: boolean }
+transpileOnly: boolean | { swc: boolean | swc.Options }

@jrieken
Copy link
Member

jrieken commented Oct 14, 2022

i want to build vscode with swc

Be careful what you wish for. Yes SWC is very fast, yes we like it and yet we use it for running tests BUT the generated JS is different. Const enums aren't inlined (runtime performance difference), imports for type-only references aren't removed, different utils are used etc.

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.

2 participants