What's the difference between `tsc --build --clean` vs. `rm -rf *.js`?

11.8k Views Asked by At

I have a quick question on the tsc command being used with the arguments --build --clean, which I understand is used for cleaning /wiping off the .js files generated earlier by the Transpiler (tsc).

What is the speciality or significance of this command? If at all I need to remove all the .js files, I can easily accomplish it through rm -rf *.js or del *.js in the directory.

Can someone educate me on the missing pieces if any?

2

There are 2 best solutions below

11
ruohola On BEST ANSWER

The difference is that rm will happily delete any files, even if they weren't generated by transpiling TypeScript.

NOTE!

tsc --build --clean will only delete .js files if there is a corresponding .ts file that it would have been generated from. This means that, if you rename .ts files, delete .ts files, or create new .ts files, and then run tsc --build --clean, old .js files that previously had corresponding .ts files will no longer be deleted.

If you really want to clean up before a build, especially when the set of .ts files has changed, you should instead delete your output folder a different way. For example rm -rf dist/ in a unix shell, or rm -r -fo dist/ in Windows PowerShell. Or, assuming you probably use Node.js if you use TypeScript, use a cross-platform package like rimraf to delete your output folder.

0
Randy Hudson On

The difference is --clean is useless in general. If you have ever renamed, moved, or deleted a source file, clean will not clean up the transpiled output.