I am working on HTML+TS+CSS project with VS2015. Is it possible to add JS file to combined TS output file? If so how to do that?
2 Answers
You can use the setting allowJs.
Allow JavaScript files to be compiled.
When combined with the outFile setting, it'll output the JS files to the combined file as well as the compiled TS.
To test I made a quick web app, that included bootstrap and jquery and what not.
I then also added a custom JS file, a custom TS file, and a tsconfig.json.
This is the contents of the tsconfig.json file:
{
"compilerOptions": {
"allowJs": true,
"outFile": "../output.js",
"alwaysStrict": true,
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
Looking at the output.js, I can see bootstrap, jquery, and both my custom scripts.
Note that I put the output file outside of the project directory. This is because by default the TS compiler will pull in all TS and JS files in the project. So if the output file is in the project, and all files in the project are included ... you get an error message telling you that's not a good idea.
You can control what files and paths are included and excluded by using the excluded and included properties in the tsconfig.json.
e.g.
{
"compilerOptions": {
"allowJs": true,
"outFile": "output.js",
"alwaysStrict": true,
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"exclude": [
"node_modules",
"Scripts/bootstrap.js",
"Scripts/jquery-1.10.2.js",
"output.js"
]
}