-
Notifications
You must be signed in to change notification settings - Fork 722
/
rollup.config.mjs
65 lines (59 loc) · 1.54 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
import fs from 'node:fs/promises';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import { dts } from 'rollup-plugin-dts';
/**
* @param {string} path
* @returns {Promise<boolean>}
*/
async function pathExists(path) {
try {
await fs.access(path);
return true;
} catch (_err) {
return false;
}
}
const PACKAGE_JSON_PATH = './package.json';
if (!pathExists(PACKAGE_JSON_PATH)) {
throw new Error(`Expected "${PACKAGE_JSON_PATH}" path to exist`);
}
const packageJsonObject = JSON.parse(await fs.readFile(PACKAGE_JSON_PATH));
const packageDependencies = Object.keys(packageJsonObject.dependencies ?? {});
/** @type {!import("rollup").MergedRollupOptions[]} */
export default [
{
input: './src/index.ts',
external: packageDependencies,
output: [
{
dir: './lib/esm',
format: 'esm',
sourcemap: true,
sourcemapPathTransform: (relativeSourcePath) => {
// Rollup seems to generate source maps pointing to the wrong directory. Ugly patch to fix it
if (relativeSourcePath.startsWith('../')) {
return relativeSourcePath.slice(3);
} else {
return relativeSourcePath;
}
},
},
],
plugins: [
typescript({
tsconfig: './tsconfig.esm.json',
}),
terser(),
],
},
{
input: 'lib/esm/index.d.ts',
output: [{ file: 'lib/esm/index.d.ts', format: 'es' }],
plugins: [
dts({
tsconfig: './tsconfig.esm.json',
}),
],
},
];