-
Notifications
You must be signed in to change notification settings - Fork 2
/
tsdx.config.js
72 lines (65 loc) · 2.14 KB
/
tsdx.config.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// const alias = require('@rollup/plugin-alias');
const ttypescript = require('ttypescript');
const tsPlugin = require('rollup-plugin-typescript2');
module.exports = {
rollup(config, options) {
const tsconfigPath = options.tsconfig || 'tsconfig.json';
// https://github.com/formium/tsdx/issues/91#issuecomment-754332423
// Until tsdx supports path aliases out of the box
// this converts aliased imports e.g.
// import { Agent } from '@/api/internal';
// to relative paths
// import { Agent } from './api/internal';
// in the build (both ts and js output)
const tsconfigJSON = ttypescript.readConfigFile(
tsconfigPath,
ttypescript.sys.readFile
).config;
const tsCompilerOptions = ttypescript.parseJsonConfigFileContent(
tsconfigJSON,
ttypescript.sys,
'./'
).options;
const customRPT2Plugin = tsPlugin({
typescript: ttypescript,
tsconfig: options.tsconfig,
tsconfigDefaults: {
exclude: [
// all TS test files, regardless whether co-located or in test/ etc
'**/*.spec.ts',
'**/*.test.ts',
'**/*.spec.tsx',
'**/*.test.tsx',
// TS defaults below
'node_modules',
'bower_components',
'jspm_packages',
'dist',
],
compilerOptions: {
sourceMap: true,
declaration: true,
jsx: 'react',
},
},
tsconfigOverride: {
compilerOptions: {
// TS -> esnext, then leave the rest to babel-preset-env
target: 'esnext',
// don't output declarations more than once
...(!options.writeMeta
? { declaration: false, declarationMap: false }
: {}),
},
},
check: !options.transpileOnly && options.writeMeta,
useTsconfigDeclarationDir: Boolean(
tsCompilerOptions && tsCompilerOptions.declarationDir
),
});
const rpt2Plugin = config.plugins.find(p => p.name === 'rpt2');
const rpt2PluginIndex = config.plugins.indexOf(rpt2Plugin);
config.plugins.splice(rpt2PluginIndex, 1, customRPT2Plugin);
return config;
},
};