sucrase icon indicating copy to clipboard operation
sucrase copied to clipboard

How to generate source maps

Open kiliancs opened this issue 5 years ago • 4 comments

Looking at the source code I see that by providing sourceMapOptions and a filePath Sucrase should generate source maps. I also see that the filePath option is provided by the webpack loader. In the same context of webpack, how do I obtain the compiledFilename, which is a mandatory prop of sourceMapOptions?

This naive loader configuration doesn't seem to be producing source maps:

const sucraseLoader = {
    loader: '@sucrase/webpack-loader',
    options: {
        transforms: ['jsx', 'typescript', 'imports'],
        sourceMapOptions: { compiledFilename: '' },
    },
};

Thank you in advance!

kiliancs avatar Apr 03 '19 22:04 kiliancs

Is there a way to generate source maps with the cli too?

remorses avatar Mar 22 '20 09:03 remorses

As for webpack, take a look a this (I believe it makes the sucrase website.) https://github.com/alangpierce/sucrase/blob/4163973a06fa9f4ac9a2d6b9cc0f04b343fe643d/website/config/webpack.config.dev.js

johnpangalos avatar Apr 21 '20 14:04 johnpangalos

In theory source maps are not needed with sucrase because the compiler preserves line numbers.

You can just look at the JS it generates without the type annotations.

Raynos avatar Apr 21 '20 14:04 Raynos

I believe we have gotten source maps created and the chrome debugger using these to point directly to the source files. The last part is this PR for anyone coming across this. https://github.com/backstage/backstage/pull/5841

jbolda avatar May 28 '21 16:05 jbolda