-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrollup.config.js
82 lines (73 loc) · 1.85 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
const createBabelConfig = require('./babel.config.js')
const resolve = require('@rollup/plugin-node-resolve')
const babelPlugin = require('@rollup/plugin-babel')
const commonjs = require('@rollup/plugin-commonjs')
const { dts } = require('rollup-plugin-dts')
const banner2 = require('rollup-plugin-banner2')
const extensions = ['.ts', '.tsx']
const cscComment = `'use client';\n`
function getBabelOptions() {
return {
...createBabelConfig,
extensions,
babelHelpers: 'bundled',
comments: false,
}
}
function createDeclarationConfig(input, output) {
return {
input,
output: {
file: output,
format: 'es',
},
plugins: [dts()],
}
}
function createESMConfig(input, output) {
return {
input,
output: { file: output, format: 'esm' },
plugins: [
resolve({ extensions }),
commonjs(),
babelPlugin(getBabelOptions()),
banner2(() => cscComment),
],
}
}
function createCommonJSConfig(input, output) {
return {
input,
output: { file: output, format: 'cjs' },
plugins: [
resolve({ extensions }),
commonjs(),
babelPlugin(getBabelOptions()),
banner2(() => cscComment),
],
}
}
function createUMDConfig(input, output, name) {
return {
input,
output: { file: output, format: 'umd', name },
plugins: [
resolve({ extensions }),
commonjs(),
babelPlugin(getBabelOptions()),
banner2(() => cscComment),
],
}
}
module.exports = (args) => {
const packageName = args.package
const input = `packages/${packageName}/src/index.ts`
const output = `packages/${packageName}/dist`
return [
createDeclarationConfig(input, `${output}/index.d.ts`),
createESMConfig(input, `${output}/index.mjs`),
createCommonJSConfig(input, `${output}/index.cjs`),
createUMDConfig(input, `${output}/index.umd.js`, packageName),
]
}