-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
100 lines (96 loc) · 2.22 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
90
91
92
93
94
95
96
97
98
99
100
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// @ts-check
import { babel, getBabelOutputPlugin } from '@rollup/plugin-babel'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import { readFile } from 'node:fs/promises'
/**
* @returns {Promise<import('./package.json')>}
*/
async function readPackageJson() {
const data = await readFile('./package.json', 'utf-8')
return JSON.parse(data)
}
/**
* @returns {Promise<import('rollup').RollupOptions[]>}
*/
export default async function () {
const pkg = await readPackageJson()
const input = 'src/index.ts'
const plugins = [
nodeResolve(),
babel({
babelHelpers: 'bundled'
})
]
const node = getBabelOutputPlugin({
presets: [
[
'@babel/preset-env',
/** @type {import('@babel/preset-env').Options} */ ({
targets: { node: pkg.engines.node.match(/[0-9]+/)?.[0] }
})
]
]
})
const browser = getBabelOutputPlugin({
presets: [
[
'@babel/preset-env',
/** @type {import('@babel/preset-env').Options} */ ({
modules: 'umd',
targets: { browsers: pkg.browserslist }
})
]
],
moduleId: 'rison2'
})
return [
{
input,
output: {
dir: 'lib',
entryFileNames: '[name].js',
format: 'esm',
preserveModules: true,
sourcemap: true
},
plugins: [
...plugins,
node,
typescript({
declaration: true,
declarationDir: 'lib',
include: ['src/**/*.ts'],
exclude: [
'**/*.test.ts',
'**/*.spec.ts',
'**/__tests__/**/*.ts',
'**/__mocks__/**/*.ts'
]
})
]
},
{
input,
output: {
dir: 'lib',
entryFileNames: '[name].cjs',
format: 'cjs',
preserveModules: true,
sourcemap: true
},
plugins: [...plugins, node, typescript()]
},
{
input,
output: {
dir: 'dist',
entryFileNames: 'rison2.js',
format: 'esm',
sourcemap: true
},
plugins: [...plugins, browser, typescript()]
}
]
}