-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
79 lines (76 loc) · 2.05 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
/* eslint-disable */
import del from 'rollup-plugin-delete'
import { terser } from 'rollup-plugin-terser'
import typescript from 'rollup-plugin-ts'
import cleanup from 'rollup-plugin-cleanup'
import transformDefaultExport from 'ts-transform-default-export'
import transformMacros from 'typescript-transform-macros'
const INPUT_FILE = 'src/index.ts'
const OUT_DIR = 'build'
export default {
input: INPUT_FILE,
output: [
{
dir: OUT_DIR,
format: 'cjs',
sourcemap: true,
exports: 'default',
entryFileNames: '[name].js',
plugins: [],
},
{
dir: OUT_DIR,
format: 'umd',
sourcemap: true,
name: 'outmatch',
exports: 'default',
entryFileNames: '[name].umd.js',
plugins: [terser()],
},
{
dir: OUT_DIR,
format: 'es',
sourcemap: true,
entryFileNames: '[name].es.mjs',
plugins: [],
},
],
plugins: [
del({ targets: `${OUT_DIR}/*` }),
typescript(
(() => {
// We don't want to transform the default export for the ES bundle. However,
// there is apparently no way to tell what the current output format is
// in the context of the transformer factory, so we do it in a hacky way.
let currentFormat
return {
hook: {
outputPath(path, kind) {
if (kind === 'declaration') {
if (path.endsWith('.es.d.ts')) {
currentFormat = 'es'
} else if (path.endsWith('.umd.d.ts')) {
currentFormat = 'umd'
} else {
currentFormat = 'cjs'
}
}
},
},
transformers: ({ program }) => {
return {
before: transformMacros(program),
afterDeclarations:
currentFormat === 'es' ? undefined : transformDefaultExport(program),
}
},
}
})()
),
// Remove all comments except JSDoc
cleanup({
comments: /^\*/,
extensions: ['ts'],
}),
],
}