-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
78 lines (71 loc) · 2.15 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
/* 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) 2022 ${pkg.author}`,
`License: ${pkg.license}`,
]);
const defaults = {
input: 'src/index.ts',
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
};
export default [
// ESM build + type declarations
{
...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
{
...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' },
],
}),
],
},
];