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

Allow --sourceMap command line flag (and others) in build mode (--build) #45130

Closed
5 tasks done
BTOdell opened this issue Jul 20, 2021 · 2 comments
Closed
5 tasks done

Comments

@BTOdell
Copy link

BTOdell commented Jul 20, 2021

Suggestion

Currently, the --sourceMap command line flag does not work when running in build mode.

D:\Programming\MyProject>tsc --build --sourceMap false
error TS5094: Compiler option '--sourceMap' may not be used with '--build'.

🔍 Search Terms

source map command line build mode tsconfig solution

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Allow the --sourceMap command line flag to be used in build mode to act as a global override for the tsconfig file(s). So if any tsconfig project files enable source map generation, then setting this flag from the command line will disable it for the entire build (including referenced tsconfigs).

This type of override behavior could also be supported for other boolean command line flags, such as --skipLibCheck and --removeComments. Essentially, flags that affect the speed or output of file generation but not affecting language parsing or interpretation.

📃 Motivating Example

./tsconfig.base.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "composite": true,
    "declaration": true,
    ...
    "sourceMap": true
  }
}

./src/tsconfig.json

{
  "extends": "../tsconfig.base.json",
  "compilerOptions": {
    "outDir": "../dist"
  }
}
D:\Programming\MyProject>tsc --build --sourceMap false

Should override the "sourceMap" config in the tsconfig.base.json and never output source maps.

💻 Use Cases

When building a TypeScript project for release on the NPM registry, often you'll want to skip generating source maps unless you plan on including the source .ts files along with the .js.map files. If you simply omit including the .js.map files in your package, then tools like Webpack will complain that it can't find the source map files. If you try including the .js.map files in your package, then you'll start getting warnings from Webpack that it can't find the source .ts files. So you end up having to include the source code in your release packages on NPM. This results in bloated release download sizes.

A solution for those projects with single tsconfig file builds is to create a second tsconfig file that extends your main tsconfig file and sets the sourceMap config to false. However, this problem and suggestion isn't about projects with simple builds. It's about complex "solution-style" builds heavily utilizing project references where it's not feasible to have an auxiliary tsconfig file alongside each of your main tsconfig files.

If the option to globally override a configuration setting was available, then you could leave the sourceMap config set to true for development and debug, and in a "prepublishOnly" script in your package.json you could compile your code with source maps completely disabled for release publishing.

@MartinJohns
Copy link
Contributor

Duplicate of #25613.

@BTOdell
Copy link
Author

BTOdell commented Jul 21, 2021

Ah, thanks. Not sure why that issue didn't show up in my search. Maybe my eyes glossed over it...

@BTOdell BTOdell closed this as completed Jul 21, 2021
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

No branches or pull requests

2 participants