Reputation: 11599
I have a few typescript files for my app myapp
in my Visual Studio 2017 ASP.NET project. I use a gulp task to generate the JS files, so I don't want the build or language service creating these JS and JS.MAP files.
This is how my TSCONFIG file look like:
{
"compileOnSave": false,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "system",
"types": [ "" ],
"lib": [
"es6",
"dom"
]
},
"include": [
"./myapp/**/*"
]
}
I tried the following:
I added the myapp
to the exclude
section of the tsconfig.js. Both the js and js.map are not generated at that time if I close Visual Studio and open again. But I see a lot of compilation errors.
I added <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
to the .csproj
file. I closed VS 2017, opened again and did a build. I see the JS and JS.MAP files.
I changed the BuildAction
property to none, but still see the JS and JS.MAP files
What should I do so the syntax check of the TS file will work but does not generate any JS and JS.MAP files?
Upvotes: 21
Views: 14246
Reputation: 125
My issue was I had accidentally deleted "outDir" from my tsconfig.json
.
To fix, I added the line back in:
{
"compilerOptions": {
...
"outDir": "./dist",
...
}
}
From the Typescript Docs - Out Dir:
If specified,
.js
(as well as.d.ts
,.js.map
, etc.) files will be emitted into this directory. The directory structure of the original source files is preserved; see rootDir if the computed root is not what you intended.
If not specified,
.js
files will be emitted in the same directory as the.ts
files they were generated from
Upvotes: 0
Reputation: 10258
I noticed that if I created the file using angular it didn't emit a .js but if I added a new TypeScript file from Visual Studio via the New Item menu it did. Turns out the latter sets the Build Action to "TypeScript file" whereas the former sets the build action to None, Do Not Copy. I changed the offending TypeScript files to None and it's stopped the .js files being generated. This is contrary to the OPs statement that it had no affect - but in my case it worked. Setting noEmit: true just resulted in no vendor.js file being generated for my angular ng build.
Upvotes: 1
Reputation: 81
If Visual Studio seems to be ignoring the noemit option in the tsconfig file, edit your project file. In the project file, go to the <PropertyGroup>
that contains the rest of the TypeScript options and add <TypeScriptNoEmit>True</TypeScriptNoEmit>
between that PropertyGroup's open and closing tags.
Upvotes: 3
Reputation: 161
Try add "noEmitOnError": true
in your tsconfig. It should prevent the .js .js.map from generating if there is any error in the TS files(s).
Upvotes: 5
Reputation: 641
Try add "noEmit": true
in your tsconfig
. It should prevent the .js .js.map from generating.
Upvotes: 16