-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
106 lines (98 loc) · 2.72 KB
/
rollup.config.mjs
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
104
105
106
/* eslint-disable import/no-extraneous-dependencies, import/no-default-export */
// Using rollup-plugin-typescript2 rather than the official one as there are problems
// with generating type declarations
// https://github.com/rollup/plugins/issues/105
// https://github.com/rollup/plugins/issues/247
//
// import typescript from '@rollup/plugin-typescript'
import typescript from 'rollup-plugin-typescript2';
import copy from 'rollup-plugin-copy';
import pkg from './package.json' assert { type: 'json' };
// rollup-plugin-banner does not work anymore and the default banner will do since there are no
// minified builds.
const createBanner = (lines) => `/**\n${lines.map((l) => ` * ${l}\n`).join('')} */`;
const banner = createBanner([
`${pkg.name} v${pkg.version}`,
`Copyright (c) 2024 ${pkg.author}`,
`License: ${pkg.license}`,
]);
const defaults = {
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
};
export default [
// ESM build + type declarations
{
input: 'src/index.ts',
...defaults,
output: {
file: pkg.exports['.'].import.default,
format: 'es',
banner,
},
plugins: [
typescript({
tsconfig: 'tsconfig.json',
tsconfigOverride: {
compilerOptions: {
declaration: true,
declarationDir: './dist/types',
},
exclude: ['./test'],
},
useTsconfigDeclarationDir: true,
}),
],
},
// Common JS build
{
input: 'src/index.ts',
...defaults,
output: {
file: pkg.exports['.'].require.default,
format: 'cjs',
banner,
},
plugins: [
typescript(),
copy({
targets: [
// TypeScript requires 2 distinct files for ESM and CJS types. See:
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/
// https://github.com/gxmari007/vite-plugin-eslint/pull/60
// Copy for ESM types is made in CJS bundle to ensure the declaration file generated in
// the previous bundle exists.
{ src: 'dist/types/index.d.ts', dest: 'dist/types', rename: 'index.d.mts' },
{ src: 'dist/types/shortcut_key.d.ts', dest: 'dist/types', rename: 'shortcut_key.d.mts' },
],
}),
],
},
// ./shortcut_key
{
input: 'src/shortcut_key.ts',
...defaults,
output: {
file: pkg.exports['./shortcut_key'].import.default,
format: 'es',
banner,
},
plugins: [
typescript(),
],
},
{
input: 'src/shortcut_key.ts',
...defaults,
output: {
file: pkg.exports['./shortcut_key'].require.default,
format: 'cjs',
banner,
},
plugins: [
typescript(),
],
},
];