Skip to content
This repository was archived by the owner on Mar 17, 2024. It is now read-only.

Commit 3aebce3

Browse files
authored
Merge pull request #161 from ts-graphviz/rollup-dts
rollup .d.ts and provides .min.js
2 parents c1cd343 + 7febaeb commit 3aebce3

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@testing-library/react": "^10.0.4",
4848
"@testing-library/react-hooks": "^3.2.1",
4949
"@types/fs-extra": "^8.1.0",
50+
"@types/glob": "^7.1.3",
5051
"@types/prop-types": "^15.7.3",
5152
"@types/react": "^16.9.17",
5253
"@types/react-dom": "^16.9.4",
@@ -64,13 +65,15 @@
6465
"eslint-plugin-react": "^7.19.0",
6566
"eslint-plugin-react-hooks": "^4.0.0",
6667
"fs-extra": "^9.0.0",
68+
"glob": "^7.1.6",
6769
"jest": "^25.3.0",
6870
"jest-graphviz": "^0.3.1",
6971
"prettier": "^2.0.5",
7072
"react": "^16.13.1",
7173
"react-dom": "^16.13.1",
7274
"react-test-renderer": "^16.13.1",
7375
"rollup": "^2.6.1",
76+
"rollup-plugin-dts": "^1.4.9",
7477
"rollup-plugin-terser": "^5.3.0",
7578
"rollup-plugin-typescript2": "^0.27.0",
7679
"ts-graphviz": "^0.13.1",

rollup.build.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { rollup } from 'rollup';
22
import typescript from 'rollup-plugin-typescript2';
33
import { terser } from 'rollup-plugin-terser';
44
import commonjs from '@rollup/plugin-commonjs';
5-
import { remove } from 'fs-extra';
5+
import dts from 'rollup-plugin-dts';
6+
import { remove, removeSync } from 'fs-extra';
7+
import glob from 'glob';
68

79
async function build({
810
input,
@@ -27,7 +29,6 @@ async function build({
2729
},
2830
},
2931
}),
30-
terser(),
3132
],
3233
external,
3334
});
@@ -36,10 +37,37 @@ async function build({
3637
format: 'cjs',
3738
file: `${output}/index.js`,
3839
}),
40+
bundle.write({
41+
format: 'cjs',
42+
file: `${output}/index.min.js`,
43+
plugins: [terser()],
44+
}),
3945
bundle.write({
4046
format: 'esm',
4147
file: `${output}/index.mjs`,
4248
}),
49+
bundle.write({
50+
format: 'esm',
51+
file: `${output}/index.min.mjs`,
52+
plugins: [terser()],
53+
}),
54+
]);
55+
}
56+
57+
async function rollupDts({ output, external }: { output: string; external: string[] }): Promise<void> {
58+
const bundle = await rollup({
59+
input: `${output}/index.d.ts`,
60+
plugins: [dts()],
61+
external,
62+
});
63+
64+
glob.sync(`${output}/**/*.d.ts`).forEach((file) => removeSync(file));
65+
66+
await Promise.all([
67+
bundle.write({
68+
format: 'es',
69+
file: `${output}/index.d.ts`,
70+
}),
4371
]);
4472
}
4573

@@ -49,6 +77,10 @@ async function build({
4977
input: 'src/index.ts',
5078
output: 'lib',
5179
declaration: true,
52-
external: ['react', 'react-dom/server', 'ts-graphviz', 'prop-types', 'react-reconciler', '@hpcc-js/wasm'],
80+
external: ['react', 'react-dom/server', 'ts-graphviz', 'prop-types', 'react-reconciler'],
81+
});
82+
await rollupDts({
83+
output: 'lib',
84+
external: ['react', 'react-dom/server', 'ts-graphviz', 'prop-types', 'react-reconciler'],
5385
});
5486
})();

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,14 @@
755755
dependencies:
756756
"@types/node" "*"
757757

758+
"@types/glob@^7.1.3":
759+
version "7.1.3"
760+
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
761+
integrity sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==
762+
dependencies:
763+
"@types/minimatch" "*"
764+
"@types/node" "*"
765+
758766
"@types/graceful-fs@^4.1.2":
759767
version "4.1.3"
760768
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f"
@@ -807,6 +815,11 @@
807815
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
808816
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
809817

818+
"@types/minimatch@*":
819+
version "3.0.3"
820+
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
821+
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
822+
810823
"@types/node@*":
811824
version "14.0.27"
812825
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.27.tgz#a151873af5a5e851b51b3b065c9e63390a9e0eb1"
@@ -5098,6 +5111,13 @@ rimraf@^3.0.0:
50985111
dependencies:
50995112
glob "^7.1.3"
51005113

5114+
rollup-plugin-dts@^1.4.9:
5115+
version "1.4.9"
5116+
resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-1.4.9.tgz#936e4cc1139d81c5c0ce64dc1e9fe025bb3eccaf"
5117+
integrity sha512-ikEIpVKDhgNFouGQemmVeXojpxEhgSUCPrfEbiDMWg3YmDWYoNifmbmt5AiBqf3KHnv/6Se5+KSgDE11oVlZYg==
5118+
optionalDependencies:
5119+
"@babel/code-frame" "^7.10.4"
5120+
51015121
rollup-plugin-terser@^5.3.0:
51025122
version "5.3.0"
51035123
resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-5.3.0.tgz#9c0dd33d5771df9630cd027d6a2559187f65885e"

0 commit comments

Comments
 (0)