-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrollup.config.ts
More file actions
138 lines (128 loc) · 3.95 KB
/
rollup.config.ts
File metadata and controls
138 lines (128 loc) · 3.95 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import bundleSize from 'rollup-plugin-output-size';
import { fileURLToPath } from 'node:url';
import { readFileSync } from 'node:fs';
import { glob } from 'glob';
import * as path from 'node:path';
import type { InputOptions, RollupOptions, SourcemapPathTransformOption } from 'rollup';
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'));
const banner = `
/*! ================================
${pkg.name} v${pkg.version}
(c) 2020-present ${pkg.author}
Released under ${pkg.license} License
================================== */
`;
const commonConfig: InputOptions = {
external: [
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {})
],
plugins: [
// it doesn't find the config by default and doesn't emit interface files
// eslint-disable-next-line max-len
// todo -https://github.com/rollup/plugins/pull/791/files#diff-77ceb76f06466d761730b952567396e6b5c292cc4044441cdfdf048b4614881dR83 check those tests
typescript({ tsconfig: './build.tsconfig.json' }),
terser({
format: {
comments: (_node, comment) => {
if (comment.type === 'comment2') {
return comment.value.includes('@upfront');
}
return false;
}
}
}),
bundleSize()
]
};
const sourcemapPathTransform: SourcemapPathTransformOption = relativeSourcePath => {
return relativeSourcePath.replaceAll('.ts', '.d.ts')
.replaceAll('src/', 'types/');
};
const rollupConfig: RollupOptions[] = [
{
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
sourcemapPathTransform,
banner
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
sourcemapPathTransform,
banner
}
],
...commonConfig
},
{
input: Object.fromEntries(
glob.sync('src/Support/{array,string,function}/*.ts').map(file => [
// This removes `src/` as well as the file extension from each
// file, so e.g., src/nested/foo.js becomes nested/foo
path.relative(
'src',
file.slice(0, file.length - path.extname(file).length)
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url))
])
),
output: {
format: 'es',
sourcemap: true,
sourcemapPathTransform,
dir: './'
},
...commonConfig
},
{
input: 'src/array.ts',
output: [
{
file: 'array.min.cjs',
format: 'cjs',
sourcemap: true,
sourcemapPathTransform,
banner
},
{
file: 'array.es.min.js',
format: 'es',
sourcemap: true,
sourcemapPathTransform,
banner
}
],
...commonConfig
},
{
input: 'src/string.ts',
output: [
{
file: 'string.min.cjs',
format: 'cjs',
sourcemap: true,
sourcemapPathTransform,
banner
},
{
file: 'string.es.min.js',
format: 'es',
sourcemap: true,
sourcemapPathTransform,
banner
}
],
...commonConfig
}
];
export default rollupConfig;