forked from svelte-add/svelte-add
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
89 lines (77 loc) · 2.43 KB
/
rollup.config.js
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
import fs from 'node:fs';
import path from 'node:path';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars';
import { preserveShebangs } from 'rollup-plugin-preserve-shebangs';
import esbuild from 'rollup-plugin-esbuild';
import dts from 'rollup-plugin-dts';
/** @type {import("rollup").RollupOptions[]} */
const dtsConfigs = [];
/**
* @param {string} project
*/
function getConfig(project) {
const inputs = [];
let outDir = '';
inputs.push(`./packages/${project}/index.ts`);
if (project == 'core') inputs.push(`./packages/${project}/internal.ts`);
outDir = `./packages/${project}/build`;
const projectRoot = path.resolve(path.join(outDir, '..'));
fs.rmSync(outDir, { force: true, recursive: true });
/** @type {import("./packages/core/utils/common.js").Package} */
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
// any dep under `dependencies` is considered external
const externalDeps = Object.keys(pkg.dependencies ?? {});
// externalizes `svelte-add` and `@svelte-add/` deps while also bundling `/clack` and `/adders`
const external = [/^(svelte-add|@svelte-add\/(?!clack|adders)\w*)/g, ...externalDeps];
/** @type {import("rollup").RollupOptions} */
const config = {
input: inputs,
output: {
dir: outDir,
format: 'esm',
sourcemap: true,
},
external,
plugins: [
preserveShebangs(),
esbuild({ tsconfig: 'tsconfig.json', sourceRoot: projectRoot }),
nodeResolve({ preferBuiltins: true, rootDir: projectRoot }),
commonjs(),
json(),
dynamicImportVars(),
],
};
// only generate dts files for libs
if ('exports' in pkg) {
// entry points need to have their own individual configs,
// otherwise the `build` dir will generate unnecessary nested dirs
// e.g. `packages/cli/build/packages/cli/index.d.ts` as opposed to: `packages/cli/build/index.d.ts`
for (const input of inputs) {
dtsConfigs.push({
input,
output: {
dir: outDir,
},
external,
plugins: [dts()],
});
}
}
return config;
}
export default [
getConfig('clack-core'),
getConfig('clack-prompts'),
getConfig('ast-tooling'),
getConfig('ast-manipulation'),
getConfig('config'),
getConfig('core'),
getConfig('cli'),
getConfig('testing-library'),
getConfig('tests'),
getConfig('dev-utils'),
...dtsConfigs,
];