forked from alex8088/electron-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
64 lines (60 loc) · 1.73 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
import { createRequire } from 'node:module'
import fs from 'node:fs/promises'
import { type Plugin, defineConfig } from 'rollup'
import ts from '@rollup/plugin-typescript'
import resolve from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'
import dts from 'rollup-plugin-dts'
const require = createRequire(import.meta.url)
const pkg = require('./package.json')
const external = ['esbuild', ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]
function clean(when: 'buildStart' | 'buildEnd', target: string): Plugin {
const _clean = async (target): Promise<void> => {
await fs.rm(target, { recursive: true, force: true }).catch(() => {})
}
return {
name: 'clean',
buildStart: async (): Promise<void> => {
if (when !== 'buildStart') return
await _clean(target)
},
buildEnd: async (): Promise<void> => {
if (when !== 'buildEnd') return
await _clean(target)
}
}
}
export default defineConfig([
{
input: ['src/index.ts', 'src/cli.ts'],
output: [
{
dir: 'dist',
entryFileNames: '[name].cjs',
chunkFileNames: 'chunks/lib-[hash].cjs',
format: 'cjs'
},
{
dir: 'dist',
entryFileNames: '[name].mjs',
chunkFileNames: 'chunks/lib-[hash].mjs',
format: 'es'
}
],
external,
plugins: [
clean('buildStart', 'dist'),
json(),
ts({ compilerOptions: { rootDir: 'src', declaration: true, declarationDir: 'dist/types' } }),
resolve()
],
treeshake: {
moduleSideEffects: false
}
},
{
input: 'dist/types/index.d.ts',
output: [{ file: pkg.types, format: 'es' }],
plugins: [dts(), clean('buildEnd', 'dist/types')]
}
])