-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtsup.config.ts
103 lines (95 loc) · 2.51 KB
/
tsup.config.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
import { defineConfig, Format, type Options } from 'tsup';
import { createUmdWrapper } from './umd-wrapper-plugin.mjs';
import { dependencies } from './package.json';
const externalDependencies = Object.keys(dependencies);
const clientName = 'quranjsApi';
const clientVersion = `{{VERSION_TO_REPLACE}}`;
const baseConfig: Options = {
entry: ['src/index.ts'],
outDir: 'dist',
outExtension({ format, options }) {
const ext = format === 'esm' ? 'mjs' : 'js';
const finalFormat = format === 'cjs' || format === 'esm' ? '' : format;
const outputExtension = options.minify
? `${finalFormat}.min.${ext}`
: `${finalFormat}.${ext}`;
return {
js: outputExtension.startsWith('.')
? outputExtension
: `.${outputExtension}`,
};
},
treeshake: true,
splitting: false,
sourcemap: true,
clean: true,
dts: true,
};
const umdConfig: Options = {
...baseConfig,
platform: 'browser',
target: ['chrome90', 'edge90', 'firefox90', 'opera98', 'safari15'],
format: ['umd' as Format],
noExternal: externalDependencies,
banner: { js: `/* @QuranJS/API version ${clientVersion} */\n` },
define: {
__VERSION__: `'${clientVersion}'`,
},
name: '@quranjs/api',
globalName: clientName,
bundle: true,
esbuildPlugins: [],
};
// export default defineConfig((options) => [
// {
// entry: ['src/index.ts'],
// format: ['esm', 'cjs'],
// splitting: false,
// sourcemap: true,
// clean: true,
// dts: true,
// treeshake: true,
// minify: !options.watch,
// },
// {
// // Configuration for CDNs
// entry: ['src/index.ts'],
// format: 'iife', // For CDNs (IIFE format for browsers)
// globalName: 'quran', // Global variable for browser use
// outDir: 'dist/umd',
// splitting: false,
// sourcemap: false,
// clean: true,
// dts: true,
// treeshake: true,
// minify: !options.watch,
// },
// ]);
export default defineConfig((options) => [
{
...baseConfig,
format: ['cjs', 'esm'],
minify: !options.watch,
},
{
...umdConfig,
minify: false,
plugins: [createUmdWrapper({ libraryName: clientName, external: [] })],
},
{
...umdConfig,
minify: true,
plugins: [createUmdWrapper({ libraryName: clientName, external: [] })],
},
// {
// ...umdConfig,
// minify: false,
// target: 'es5',
// outputExtension: {
// js: `browser.js`,
// },
// esbuildPlugins: [
// umdWrapper({ libraryName: clientName, external: 'inherit' }),
// ],
// },
]);