Unfortunately, this is not the default behavior of the TypeScript compiler. I myself ran into this problem when I tried to modulate a TypeScript application.
The solution I decided to use for this problem:
- Start using the old old _references.ts files.
- Do not mess with TSC (just compile with JavaScript).
- _references.ts / Gulp. :
var fs = require('fs');
var PLUGIN_NAME = 'reference-parser';
function referenceParser(fileName, prefix, filterParentReferences) {
var references = [];
var content = fs.readFileSync(fileName, 'utf8');
content = content.replace(/\/\/\/ <reference path=("|')/g, prefix);
content = content.replace(/.ts("|')\s*\/>,?/g, '.js');
function readLines(input) {
if (input.length === 0)
return;
var newLineIndex = input.indexOf('\r\n');
if (newLineIndex >= 0) {
var line = input.substring(0, newLineIndex).trim();
readLine(line);
if (input.length > (newLineIndex + 2))
readLines(input.substring(newLineIndex + 2));
} else {
readLine(input);
}
}
function readLine(line) {
if (line && line.length > 0) {
if (line.startsWith('//')) {
} else if (line.indexOf('_references.ts') >= 0) {
} else if (filterParentReferences && line.startsWith('../')) {
} else {
references.push(line);
}
}
}
readLines(content);
return references;
}
module.exports = referenceParser;
Hide result. Gulp:
var sourceFiles = referenceParser(sourceRoot + '_references.ts', buildJsRoot, true);
var sourcesStream = gulp
.src(sourceFiles)
.pipe(plugins.sourcemaps.init({ loadMaps: true }))
.pipe(plugins.concat(module.name + '.Bundle.js'))
.pipe(plugins.uglify({ mangle: false }))
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest(destinationRoot));
moduleGulpStreams.add(sourcesStream);
Hide result