generated from Arnesfield/template.ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.ts
84 lines (80 loc) · 2.69 KB
/
rollup.config.ts
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
import _eslint from '@rollup/plugin-eslint';
import _json from '@rollup/plugin-json';
import _replace from '@rollup/plugin-replace';
import _typescript from '@rollup/plugin-typescript';
import { RollupOptions } from 'rollup';
import cleanup from 'rollup-plugin-cleanup';
import dts from 'rollup-plugin-dts';
import edit from 'rollup-plugin-edit';
import esbuild from 'rollup-plugin-esbuild';
import externals from 'rollup-plugin-node-externals';
import outputSize from 'rollup-plugin-output-size';
import pkg from './package.json' with { type: 'json' };
import { helpText } from './src/help-text.js';
// NOTE: remove once import errors are fixed for their respective packages
const eslint = _eslint as unknown as typeof _eslint.default;
const json = _json as unknown as typeof _json.default;
const replace = _replace as unknown as typeof _replace.default;
const typescript = _typescript as unknown as typeof _typescript.default;
// const PROD = process.env.NODE_ENV !== 'development';
const WATCH = process.env.ROLLUP_WATCH === 'true';
const input = 'src/index.ts';
function defineConfig(options: (false | RollupOptions)[]) {
return options.filter((options): options is RollupOptions => !!options);
}
export default defineConfig([
{
input: { index: input, cli: 'src/cli.ts' },
output: {
dir: 'lib',
format: 'esm',
exports: 'named',
chunkFileNames: '[name].js'
},
plugins: [
esbuild({ target: 'esnext' }),
// only replace help text when not watching to properly
// update help-text.ts contents during development
!WATCH &&
replace({
preventAssignment: true,
'process.env.HELP': JSON.stringify(helpText())
}),
// remove dangling @isaacs/cliui import
// once it's replaced with the generated help text
edit({
chunk(data) {
const pkg = '@isaacs/cliui';
const match = `import '${pkg}';\n`;
if (data.contents.includes(match)) {
console.log(
'[edit] Removing %o import for %o.',
pkg,
data.fileName
);
return data.contents.replace(match, '');
}
}
}),
cleanup({
comments: ['some', 'sources', /__PURE__/],
extensions: ['js', 'ts']
}),
json(),
// explicitly treat @isaacs/cliui as external
// other external dev deps may be a mistake
externals({ include: ['@isaacs/cliui'] }),
outputSize()
]
},
{
input,
output: { file: pkg.types, format: 'esm' },
plugins: [dts(), externals(), outputSize()]
},
WATCH && {
input,
watch: { skipWrite: true },
plugins: [eslint(), typescript(), json(), externals()]
}
]);