-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (43 loc) · 1.45 KB
/
Copy pathindex.js
File metadata and controls
53 lines (43 loc) · 1.45 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const dts = require('dts-bundle');
const path = require('path');
module.exports = (api, options) => {
api.chainWebpack(config => {
//Disable thread-loader, cache-loader
const tsRule = config.module.rule('ts').test(/\.ts$/);
const tsxRule = config.module.rule('tsx').test(/\.tsx$/);
tsRule.uses.delete('cache-loader');
tsxRule.uses.delete('cache-loader');
tsRule.uses.delete('thread-loader');
tsxRule.uses.delete('thread-loader');
//Enable the generating of declaration files
tsRule
.use('ts-loader')
.loader('ts-loader')
.tap(opts => {
opts.compilerOptions = { declaration: true };
opts.transpileOnly = false;
opts.happyPackMode = false;
return opts;
});
});
//Bundle command
api.registerCommand('bundle-dts', {
description: 'Bundle the generated declaration files to a single file',
usage: 'vue-cli-service bundle-dts [options]',
}, async (args) => {
const config = api.resolveWebpackConfig();
const baseDir = config.output.path;
const entry = path.parse(config.entry.app[0]);
const main = path.resolve(baseDir, entry.dir, entry.name + '.d.ts');
const name = require(api.resolve('package.json')).name;
delete args['_'];
if (args.main) {
const main = path.parse(args.main);
args.main = path.resolve(baseDir, main.dir, main.name + '.d.ts');
}
dts.bundle({
...{ baseDir, main, name },
...args
});
});
}