-
-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
90 lines (82 loc) · 2.46 KB
/
tsdown.config.ts
File metadata and controls
90 lines (82 loc) · 2.46 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import path from 'node:path';
import { defineConfig, mergeConfig, type UserConfig } from 'tsdown';
import { analyzer, unstableRolldownAdapter } from 'vite-bundle-analyzer';
import pkg from './package.json' with { type: 'json' };
const banner = `
/*!
* Axios Cache Interceptor ${pkg.version}
* (c) 2021-present Arthur Fiorette & Contributors
* Released under the MIT License.
*/
`.trim();
function buildConfig(overrides: UserConfig) {
return mergeConfig(
{
entry: 'src/index.ts',
tsconfig: 'tsconfig.build.json',
clean: true,
inlineOnly: false, // Suppress bundling warnings for all formats
format: {
esm: {
platform: 'neutral',
target: ['esnext'],
sourcemap: true,
minify: !!process.env.MINIFY,
skipNodeModulesBundle: true // Don't bundle dependencies
},
cjs: {
platform: 'node',
target: ['esnext'],
sourcemap: true,
minify: !!process.env.MINIFY,
skipNodeModulesBundle: true // Don't bundle dependencies
},
umd: {
plugins: [!!process.env.BUNDLE && unstableRolldownAdapter(analyzer())],
platform: 'browser',
sourcemap: true,
minify: true, // Always minify UMD
noExternal: () => true,
banner,
globalName: 'AxiosCacheInterceptor',
// Parse dependencies source code to better tree shake them
resolve: {
alias: {
'object-code': path.resolve('./node_modules/object-code/src/index.ts'),
'http-vary': path.resolve('./node_modules/http-vary/src/index.ts'),
'cache-parser': path.resolve('./node_modules/cache-parser/src/index.ts'),
'fast-defer': path.resolve('./node_modules/fast-defer/src/index.ts')
}
},
// Keep previous output file structure
outputOptions: (options) => {
const { dir, ...rest } = options;
return {
...rest,
file: path.join(overrides.outDir ?? '', 'index.bundle.js')
};
}
}
}
},
overrides
);
}
export default defineConfig([
// Dev build with __ACI_DEV__=true
buildConfig({
outDir: 'dev',
dts: false,
define: {
__ACI_DEV__: 'true'
}
}),
// Dist build with __ACI_DEV__=false and types
buildConfig({
outDir: 'dist',
dts: true,
define: {
__ACI_DEV__: 'false'
}
})
]);