-
Notifications
You must be signed in to change notification settings - Fork 14
/
rollup.config.js
79 lines (69 loc) · 1.81 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
import path from 'node:path'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import alias from '@rollup/plugin-alias'
import html from '@rollup/plugin-html'
import esbuild from 'rollup-plugin-esbuild'
import dts from 'rollup-plugin-dts'
import serve from 'rollup-plugin-serve'
import typescript from '@rollup/plugin-typescript'
import template from './playground/template.js'
const pkg = JSON.parse(readFileSync('./package.json', { encoding: 'utf8' }))
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const configs = []
const srcDir = path.resolve(__dirname, 'src')
const input = path.resolve(__dirname, 'src/index.ts')
const pkgName = pkg.name
const output = [{
file: `${process.env.BUILD === 'prod' ? 'dist' : 'playground'}/${pkgName}.js`,
format: 'iife',
name: pkgName,
extend: true,
}]
const pluginEsbuild = process.env.BUILD === 'prod' ? esbuild({ drop: ['console'] }) : esbuild()
const pluginAlias = alias({ entries: [{ find: '@', replacement: srcDir }] })
const plugins = [pluginEsbuild, typescript({ declaration: false }), pluginAlias]
if (process.env.BUILD === 'prod') {
output.push({
file: `dist/${pkgName}.mjs`,
format: 'es',
}, {
file: `dist/${pkgName}.cjs`,
format: 'cjs',
}, {
file: `dist/${pkgName}.min.js`,
format: 'iife',
name: pkgName,
extend: true,
plugins: [
esbuild({
minify: true,
}),
],
})
configs.push({
input,
output: {
file: `dist/${pkgName}.d.ts`,
format: 'es',
},
plugins: [
dts(),
pluginAlias,
],
})
}
if (process.env.BUILD !== 'prod') {
plugins.push(html({
title: pkgName,
template,
}))
}
if (process.env.BUILD === 'dev')
plugins.push(serve('playground'))
configs.push({
input,
output,
plugins,
})
export default configs