-
Notifications
You must be signed in to change notification settings - Fork 6
/
rollup.config.js
78 lines (74 loc) · 1.83 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
import rollupTypescript from '@rollup/plugin-typescript'
import rollupJson from '@rollup/plugin-json'
import rollupCommonjs from '@rollup/plugin-commonjs'
import rollupTerser from '@rollup/plugin-terser'
import rollupAlias from '@rollup/plugin-alias'
import rollupDts from 'rollup-plugin-dts'
import fs from 'fs-extra'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import process from 'node:process'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
function getPlugins(dts = false, terser = false) {
const tsconfig = fs.readJSONSync('./tsconfig.json')
const aliasKey = `@web-resource-monitor/${process.env.PACKAGENAME}`
let plugins = [
rollupCommonjs(),
rollupJson(),
rollupAlias({
[aliasKey]: path.resolve(
__dirname,
`./packages/${process.env.PACKAGENAME}/src/index.ts`)
}),
rollupTypescript(tsconfig.compilerOptions),
]
if (terser) {
plugins.push(rollupTerser())
}
if (dts) {
plugins = [
rollupDts({
preserveSymlinks: false
}),
]
}
return plugins
}
const input = `./packages/${process.env.PACKAGENAME}/src/index.ts`
export default [
{
input,
output: [
{
file: `./packages/${process.env.PACKAGENAME}/dist/index.esm.js`,
format: 'es',
},
{
file: `./packages/${process.env.PACKAGENAME}/dist/index.js`,
format: 'cjs',
},
],
plugins: getPlugins(),
},
{
input,
output: [
{
file: `./packages/${process.env.PACKAGENAME}/dist/index.d.ts`,
format: 'es',
},
],
plugins: getPlugins(true),
},
{
input,
output: [
{
file: `./packages/${process.env.PACKAGENAME}/dist/index.min.js`,
format: 'umd',
name: 'webResourceMonitor',
},
],
plugins: getPlugins(false, true),
},
]