Skip to content

Commit 6356367

Browse files
committed
Merge pull request #175 from rob-bateman/fix-interface-dts-files
fix for declaration output to include d.ts files for interfaces
2 parents 5cc9fc5 + d22eb69 commit 6356367

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,21 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
483483
}
484484
});
485485

486+
487+
// gather all declaration files from TypeScript and output them to webpack
488+
Object.keys(instance.files)
489+
.filter(filePath => !!filePath.match(/\.ts(x?)$/))
490+
.forEach(filePath => {
491+
let output = languageService.getEmitOutput(filePath);
492+
let declarationFile = output.outputFiles.filter(filePath => !!filePath.name.match(/\.d.ts$/)).pop();
493+
if (declarationFile) {
494+
compilation.assets[declarationFile.name] = {
495+
source: () => declarationFile.text,
496+
size: () => declarationFile.text.length
497+
};
498+
}
499+
});
500+
486501
callback();
487502
});
488503

@@ -583,9 +598,6 @@ function loader(contents) {
583598

584599
var sourceMapFile = output.outputFiles.filter(file => !!file.name.match(/\.js(x?)\.map$/)).pop();
585600
if (sourceMapFile) { sourceMapText = sourceMapFile.text }
586-
587-
var declarationFile = output.outputFiles.filter(file => !!file.name.match(/\.d.ts$/)).pop();
588-
if (declarationFile) { this.emitFile(path.relative(this.options.context, declarationFile.name), declarationFile.text); }
589601
}
590602

591603
if (outputText == null) throw new Error(`Typescript emitted no output for ${filePath}`);

0 commit comments

Comments
 (0)