-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
65 lines (59 loc) · 1.51 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
import path from 'path'
import ts from 'rollup-plugin-typescript2'
import replace from '@rollup/plugin-replace'
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'
const resolve = (file) => path.resolve(__dirname, file)
const isProduction = process.env.NODE_ENV === 'production'
const simpleClone = obj => JSON.parse(JSON.stringify(obj))
const addMinSuffix = str => str.replace(/\.js$/, '.min.js')
const tsPlugin = ts({
tsconfig: resolve('tsconfig.json'),
cacheRoot: resolve('node_modules/.rts2_cache'),
tsconfigOverride: {
compilerOptions: {
declaration: isProduction
}
}
})
const defaultOutputs = ['umd', 'esm', 'cjs']
const createOutputs = (outputs) => {
const baseOutputs = Object.values(outputs)
return isProduction
? baseOutputs.concat(simpleClone(baseOutputs).map(output => {
output.file = addMinSuffix(output.file)
return output
}))
: defaultOutputs.map(output => outputs[output])
}
const outputs = {
'esm': {
file: resolve('dist/angel.esm.js'),
format: 'es'
},
'cjs': {
file: resolve('dist/angel.cjs.js'),
format: 'cjs'
},
'umd': {
file: resolve('dist/angel.umd.js'),
format: 'umd',
name: '__ANGEL__'
}
}
module.exports = {
input: resolve('lib/index.ts'),
output: createOutputs(outputs),
plugins: [
tsPlugin,
replace({
__VERSION__: `${pkg.version}`
}),
isProduction ? terser({
include: /\.min\.js$/
}) : ''
].filter(Boolean),
watch: {
exclude: 'node_modules/**'
}
}