Skip to content

Commit be0c4d7

Browse files
committed
build: generate declaration files
1 parent 4e0ba69 commit be0c4d7

File tree

3 files changed

+92
-44
lines changed

3 files changed

+92
-44
lines changed

package-lock.json

Lines changed: 39 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"prettier": "^3.2.5",
4444
"rollup": "^4.14.0",
4545
"rollup-plugin-copy": "^3.5.0",
46+
"rollup-plugin-dts": "^6.1.1",
4647
"ts-jest": "^29.1.2",
4748
"tslib": "^2.6.2",
4849
"typescript": "^5.4.3"

rollup.config.mjs

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
11
import copy from 'rollup-plugin-copy';
2+
import dts from 'rollup-plugin-dts';
23
import typescript from '@rollup/plugin-typescript';
34

4-
export default {
5-
input: 'src/index.ts',
6-
output: {
7-
dir: 'dist',
8-
format: 'cjs',
9-
},
10-
plugins: [
11-
typescript(),
12-
copy({
13-
targets: [
14-
{
15-
src: 'LICENSE',
16-
dest: 'dist',
17-
},
18-
{
19-
src: 'README.md',
20-
dest: 'dist',
21-
},
22-
{
23-
src: 'package.json',
24-
dest: 'dist',
25-
transform(content) {
26-
const ignoredProps = ['devDependencies', 'scripts'];
5+
export default [
6+
{
7+
input: 'src/index.ts',
8+
output: {
9+
dir: 'dist',
10+
format: 'cjs',
11+
},
12+
plugins: [
13+
typescript(),
14+
copy({
15+
targets: [
16+
{
17+
src: 'LICENSE',
18+
dest: 'dist',
19+
},
20+
{
21+
src: 'README.md',
22+
dest: 'dist',
23+
},
24+
{
25+
src: 'package.json',
26+
dest: 'dist',
27+
transform(content) {
28+
const ignoredProps = ['devDependencies', 'scripts'];
2729

28-
const json = JSON.parse(content.toString());
29-
return JSON.stringify(
30-
{
31-
...Object.fromEntries(
32-
Object.entries(json).filter(
33-
([key]) => !ignoredProps.includes(key),
30+
const json = JSON.parse(content.toString());
31+
return JSON.stringify(
32+
{
33+
...Object.fromEntries(
34+
Object.entries(json).filter(
35+
([key]) => !ignoredProps.includes(key),
36+
),
3437
),
35-
),
36-
main: 'index.js',
37-
},
38-
null,
39-
4,
40-
);
38+
main: 'index.js',
39+
},
40+
null,
41+
4,
42+
);
43+
},
4144
},
42-
},
43-
],
44-
}),
45-
],
46-
};
45+
],
46+
}),
47+
],
48+
},
49+
{
50+
// Generate declaration file
51+
input: 'src/index.ts',
52+
output: {
53+
file: 'dist/index.d.ts',
54+
format: 'cjs',
55+
},
56+
plugins: [dts()],
57+
},
58+
];

0 commit comments

Comments
 (0)