Skip to content

Commit e304440

Browse files
committed
Only generate source maps when gulp-sourcemaps is used
Fixes performance regression, fix #429
1 parent d706e30 commit e304440

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/compiler.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ export class ProjectCompiler implements ICompiler {
2020
host: Host;
2121
project: ProjectInfo;
2222
program: ts.Program;
23+
private hasSourceMap: boolean;
2324

2425
prepare(project: ProjectInfo) {
2526
this.project = project;
27+
this.hasSourceMap = false;
2628
}
2729

28-
inputFile(file: File) { }
30+
inputFile(file: File) {
31+
if (file.gulp.sourceMap) this.hasSourceMap = true;
32+
}
2933

3034
inputDone() {
3135
if (!this.project.input.firstSourceFile) {
@@ -43,6 +47,8 @@ export class ProjectCompiler implements ICompiler {
4347
}
4448
}
4549

50+
this.project.options.sourceMap = this.hasSourceMap;
51+
4652
const currentDirectory = utils.getCommonBasePathOfArray(
4753
rootFilenames.map(fileName => this.project.input.getFile(fileName).gulp.cwd)
4854
);
@@ -99,7 +105,7 @@ export class ProjectCompiler implements ICompiler {
99105
case 'js':
100106
case 'jsx':
101107
jsFileName = fileName;
102-
jsContent = this.removeSourceMapComment(content);
108+
jsContent = content;
103109
break;
104110
case 'd.ts':
105111
dtsFileName = fileName;
@@ -139,6 +145,9 @@ export class ProjectCompiler implements ICompiler {
139145
}
140146

141147
if (jsContent !== undefined) {
148+
if (jsMapContent !== undefined) {
149+
jsContent = this.removeSourceMapComment(jsContent);
150+
}
142151
this.project.output.writeJs(base, jsFileName, jsContent, jsMapContent, file ? file.gulp.cwd : currentDirectory, file);
143152
}
144153
if (dtsContent !== undefined) {

lib/output.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export class Output {
5151
}
5252

5353
private applySourceMap(sourceMapContent: string, original: input.File, output: VinylFile) {
54+
if (sourceMapContent === undefined) return undefined;
55+
5456
const map = JSON.parse(sourceMapContent);
5557
const directory = path.dirname(output.path);
5658

0 commit comments

Comments
 (0)