generated from juliendargelos/rollup-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
103 lines (96 loc) · 2.46 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
101
102
103
import autoExternal from 'rollup-plugin-auto-external'
import nodeResolve from '@rollup/plugin-node-resolve'
import bundleHtml from 'rollup-plugin-bundle-html'
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 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 config = {
input: 'src/index.ts',
output: { sourcemap: true },
plugins: [
build && autoExternal(),
alias({
resolve: ['.ts'],
entries: Object
.entries(tsconfig.compilerOptions.paths)
.map(([find, [replacement]]) => ({ find, replacement }))
})
]
}
export default [
build && {
...config,
output: [
{ ...config.output, file: pkg.main, format: 'cjs' },
{ ...config.output, file: pkg.module, format: 'es' }
],
plugins: [
...config.plugins,
eslint(),
ts(),
cleaner({ targets: [pkg.main.replace(/\/[^\/]+$/, '')] }),
terser()
]
},
build && {
...config,
output: {
...config.output,
file: pkg.browser,
format: 'umd',
name: pkg.name
.split(/[^a-z0-9]+/i)
.map(part => part && part[0].toUpperCase() + part.slice(1))
.join('')
},
plugins: [
...config.plugins,
ts({
transpileOnly: true,
tsconfig: tsconfig => ({ ...tsconfig, target: 'es5' })
}),
nodeResolve({ extensions: ['.ts', '.js'] }),
commonjs(),
terser()
]
},
demo && {
...config,
input: 'demo/index.ts',
output: {
...config.output,
dir: 'demo-dist',
chunkFileNames: '[name].js',
format: 'es'
},
plugins: [
...config.plugins,
ts({
tsconfig: tsconfig => ({
...tsconfig,
declaration: false
})
}),
cleaner({ targets: ['demo-dist'] }),
nodeResolve({ extensions: ['.ts', '.js'] }),
commonjs(),
bundleHtml({
template: 'demo/index.html',
dest: 'demo-dist',
ignore: /\/(?:worklet|css-paint-polyfill)\.js$/
}),
production && terser(),
development && serve('demo-dist')
]
}
].filter(Boolean)