I'm compiling all .ts
files into one file using the command
tsc -out app.js app.ts --removeComments
based on the npm usage instructions. The problem is it still keeps all reference tags in the compiled code afterwards! As far as I'm aware, there's no use for these in JavaScript.
For example, these TypeScript files
Application.ts
/// <reference path="../references/backbone.d.ts" />
module Example {
export class Application extends Backbone.View<Backbone.Model> {
...
}
}
and
app.ts
/// <reference path="Example/Application.ts" />
import Application = Example.Application;
class App extends Application {
...
}
will compile into something like
/// <reference path="../references/backbone.d.ts" />
var __extends = (this && this.__extends) || function (d, b) {
...
};
var Example;
(function (Example) {
var Application = (function (_super) {
...
})(Backbone.View);
Example.Application = Application;
})(Example || (Example = {}));
/// <reference path="Example/Application.ts" />
var Application = Example.Application;
var App = (function (_super) {
...
})(Application);
//# sourceMappingURL=app.js.map
The sourceMappingURL
I absolutely want included, and the --removeComments
works as expected there. But the reference tags seem pointless when sitting on the server. Is there an option to remove these from the compiled source? Or am I incorrect in thinking these are not used (possibly when debugging with source maps)?
There are two methods to removing the references, as pointed out in the comments.
Using tsconfig.json
removes the need for /// <reference>
tags
altogether. For example:
/// <reference path="../references/backbone.d.ts" />
becomes
{
"compilerOptions": {
...
},
"files": [
'references/backbone.d.ts'
]
}
within tsconfig.json
.
If you wish to not use a config file, minifying the compiled JavaScript with a tool like Closure Compiler will remove all comments and references.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With