-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.mts
More file actions
71 lines (67 loc) · 1.62 KB
/
rollup.config.mts
File metadata and controls
71 lines (67 loc) · 1.62 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
/**
* @file rollup
* @module config/rollup
*/
import resolve from '@rollup/plugin-node-resolve'
import type {
NormalizedOutputOptions,
OutputBundle,
PluginContext,
RollupOptions
} from 'rollup'
import { dts } from 'rollup-plugin-dts'
import pkg from './package.json' with { type: 'json' }
/**
* The list of target files.
*
* @const {ReadonlyArray<string>} files
*/
const files: readonly string[] = [
'./dist/index.d.mts',
'./dist/testing/index.d.mts'
]
/**
* The rollup configuration.
*
* @see {@linkcode RollupOptions}
*
* @type {RollupOptions[]}
*/
export default files.map(file => ({
external: file.includes('testing') ? [pkg.name] : undefined,
input: file,
output: [{ file, format: 'esm' }],
plugins: [
resolve({ extensions: ['.d.mts', '.mts'] }),
dts(),
{
/**
* Re-add lost `type` modifiers.
*
* The {@linkcode dts} plugin loses `type` modifiers during bundling.
*
* @see https://github.com/Swatinem/rollup-plugin-dts/issues/354
*
* @this {PluginContext}
*
* @param {NormalizedOutputOptions} options
* The normalized output options
* @param {OutputBundle} bundle
* The output bundle object
* @return {undefined}
*/
generateBundle(
this: PluginContext,
options: NormalizedOutputOptions,
bundle: OutputBundle
): undefined {
for (const output of Object.values(bundle)) {
if (output.type === 'chunk') {
output.code = output.code.replaceAll('import {', 'import type {')
}
}
return void this
}
}
]
}))