microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.94k stars 12.48k forks source link

Provide option to not include `sourceMappingURL` in the generated `.js` file when `sourceMap` is `true` #59896

Open sudo-barun opened 1 month ago

sudo-barun commented 1 month ago

🔍 Search Terms

✅ Viability Checklist

⭐ Suggestion

There should be a compilerOption to disable inclusion of sourceMappingURL in the generated .js file when sourceMap is true.

📃 Motivating Example

When sourceMap is true in tsconfig.json, TypeScript compiler generates .map file together with .js file and also include sourceMappingURL in .js file.

The inclusion of sourceMappingURL in .js file is one way of linking generated code with sourcemap. Another way is to use SourceMap header.

Right now, to make use of SourceMap header without including sourceMappingURL in .js file, I have to:

  1. set sourceMap to true
  2. run npx tsc
  3. set sourceMap to false
  4. run npx tsc once again.

There should provide a compilerOption to disable inclusion of sourceMappingURL in the generated .js file.

💻 Use Cases

  1. What do you want to use this for? I want to use this to use SourceMap header without getting warning in browser. The benefit of using SourceMap header is that the linking of generated file to map file can be controlled by the server without regenerating .js file.

  2. What shortcomings exist with current approaches? sourceMappingURL is included in .js file.

  3. What workarounds are you using in the meantime?

    1. set sourceMap to true
    2. run npx tsc
    3. set sourceMap to false
    4. run npx tsc once again.
RyanCavanaugh commented 1 month ago

Seems like the HTTP server could strip this automatically if it knows that it's sending a SourceMap header

sudo-barun commented 1 month ago

@RyanCavanaugh By "the HTTP server", are you referring to the http-server package?

Even if some server has such stripping feature, it does not look like standard behavior for a web server to have. Popular servers like Apache httpd and nginx do not have that feature.

RyanCavanaugh commented 1 month ago

I mean the abstract concept of an HTTP server that is in charge of the content it sends to the receiver