-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
82 lines (78 loc) · 1.96 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
import path from 'path'
import ts from 'rollup-plugin-typescript2'
import commonjs from '@rollup/plugin-commonjs'
import node from '@rollup/plugin-node-resolve'
import { terser } from 'rollup-plugin-terser'
import dts from 'rollup-plugin-dts'
import cleanup from 'rollup-plugin-cleanup'
import del from 'rollup-plugin-delete'
const outputConfigs = path => [
{
file: `${path}cjs.js`,
format: `cjs`
},
{
file: `${path}esm.js`,
format: `es`,
plugins: [
terser({
module: true,
compress: {
ecma: 2015,
pure_getters: true
},
output: { comments: false }
})
],
sourcemap: true
},
{
name: 'window',
file: `${path}global.js`,
format: `iife`,
extend: true,
sourcemap: true
}
]
const tsPlugin = ts({
check: process.env.NODE_ENV === 'production',
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'),
tsconfigOverride: {
compilerOptions: {
module: 'ES2015'
}
}
})
const defaultPlugins = [
del({ targets: ['dist/*', 'gzip/*'], runOnce: true }),
node({
browser: true,
mainFields: ['module', 'main']
}),
commonjs({
include: /node_modules/
}),
cleanup()
]
export default [
{
input: 'src/index.ts',
output: outputConfigs('dist/index.'),
plugins: [tsPlugin, ...defaultPlugins]
},
{
input: 'src/gzip/index.ts',
output: outputConfigs('gzip/'),
plugins: [tsPlugin, ...defaultPlugins]
},
{
input: 'src/gzip/index.ts',
output: [
{ file: 'gzip/index.d.ts', format: 'es' },
{ file: 'gzip/esm.d.ts', format: 'es' },
{ file: 'gzip/cjs.d.ts', format: 'es' }
],
plugins: [dts()]
}
]