forked from awslabs/diagram-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeclarationBundlePlugin.js
More file actions
38 lines (35 loc) · 999 Bytes
/
DeclarationBundlePlugin.js
File metadata and controls
38 lines (35 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { generateDtsBundle } = require('dts-bundle-generator');
class DeclarationBundlePlugin {
constructor(options = {}) {
this.name = options.name || '[name].d.ts';
delete(options.name);
this.options = options;
}
apply(compiler) {
compiler.hooks.emit.tapAsync('DeclarationBundlePlugin', (compilation, callback) => {
compilation.chunks.forEach((chunk) => {
const entryModule = chunk.entryModule.rootModule;
const config = {
filePath: entryModule.resource,
libraries: {
inlinedLibraries: this.options.inlinedLibraries
},
output: {
inlineDeclareGlobals: true
}
}
const dts = generateDtsBundle([config])[0];
compilation.assets[this.name] = {
source() {
return dts;
},
size() {
return dts.length;
}
};
});
callback();
});
}
}
module.exports = DeclarationBundlePlugin;