-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
86 lines (78 loc) · 2.09 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
import autoExternal from 'rollup-plugin-auto-external'
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import cleaner from 'rollup-plugin-cleaner'
import alias from '@rollup/plugin-alias'
import serve from 'rollup-plugin-serve'
import html from '@rollup/plugin-html'
import ts from 'rollup-plugin-ts'
import { terser } from 'rollup-plugin-terser'
import { eslint } from 'rollup-plugin-eslint'
import pkg from './package.json'
import tsconfig from './tsconfig.json'
const development = process.env.ROLLUP_WATCH
const production = !development
const demo = process.env.DEMO || development
const build = !demo
const input = 'src/index.ts'
const plugins = [
build && autoExternal(),
alias({
resolve: ['.ts'],
entries: Object
.entries(tsconfig.compilerOptions.paths)
.map(([find, [replacement]]) => ({ find, replacement }))
})
]
export default [
build && {
input,
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
plugins: [
...plugins,
eslint(),
ts(),
cleaner({ targets: [pkg.main.replace(/\/[^\/]+$/, '')] }),
]
},
build && {
input,
output: {
file: pkg.browser,
format: 'umd',
sourcemap: true,
name: pkg.name
.split(/[^a-z0-9]+/i)
.map(part => part && part[0].toUpperCase() + part.slice(1))
.join('')
},
plugins: [
...plugins,
ts({ transpileOnly: true }),
nodeResolve({ extensions: ['.ts', '.js'] }),
commonjs(),
terser()
]
},
demo && {
input: 'demo/index.ts',
output: {
file: 'demo-dist/index.js',
format: 'iife',
sourcemap: true
},
plugins: [
...plugins,
ts({ tsconfig: tsconfig => ({ ...tsconfig, declaration: false }) }),
cleaner({ targets: ['demo-dist'] }),
nodeResolve({ extensions: ['.ts', '.js'] }),
commonjs(),
html({ title: `${pkg.name} demo` }),
production && terser(),
development && serve('demo-dist')
]
}
].filter(Boolean)