ts-loader icon indicating copy to clipboard operation
ts-loader copied to clipboard

Questions about sourcemap

Open imtaotao opened this issue 2 years ago • 3 comments

Why is the upstream sourcemap not processed in the loader?

https://github.com/TypeStrong/ts-loader/blob/main/src/index.ts#L34

function loader(this: webpack.LoaderContext<LoaderOptions>, contents: string, map?: Sourcemap) {
    if (map) {
       ...
    }
}

imtaotao avatar May 12 '22 16:05 imtaotao

What processing did you have in mind?

johnnyreilly avatar May 16 '22 04:05 johnnyreilly

I have a loader that processes source files, and then passes the source code and sourcemap to ts-loader, but ts-loader doesn't seem to merge the sourcemap passed from upstream loader.

imtaotao avatar May 24 '22 07:05 imtaotao

What problems does that cause?

johnnyreilly avatar May 24 '22 11:05 johnnyreilly

https://github.com/TypeStrong/ts-loader/blob/9533b2dc992392623e04645b1972332bddef0c76/src/index.ts#L34

Currently, ts-loader force discards any source maps generated by previous loaders. In its exported loader entry function, it just silently ignores the third parameter, which is the source map returned by previous loaders. If I have some pre-processor loaders running before ts-loader, it silently discards the source maps. This is very bad. You should at lease print a warning info, if the third parameter is not null.

chipzhang avatar Mar 27 '23 07:03 chipzhang

@johnnyreilly for us specifically this causes that we are not able to debug Vue SFC TypeScript files. This is because the ts-loader is the second loader after the vue-loader and should respect the input source maps generated by the vue-loader.

I've seen that there has already been made a suggestion on how to handle this: https://github.com/TypeStrong/ts-loader/pull/1367 . I've tested the changes in one of our Vue projects and debugging works with those changes.

Ka0o0 avatar Aug 28 '23 08:08 Ka0o0