-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrollup.config.js
More file actions
99 lines (83 loc) · 2.08 KB
/
rollup.config.js
File metadata and controls
99 lines (83 loc) · 2.08 KB
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
import { join, dirname, extname, basename } from 'path'
import nodeResolver from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import json from '@rollup/plugin-json'
import clear from 'rollup-plugin-clear'
import progress from 'rollup-plugin-progress'
import externals from 'rollup-plugin-node-externals'
import typescript from 'rollup-plugin-typescript2'
import { terser } from 'rollup-plugin-terser'
import filesize from 'rollup-plugin-filesize'
import visualizer from 'rollup-plugin-visualizer'
import parsePackageName from 'parse-pkg-name'
import snakeCase from 'lodash/snakeCase'
import pkg from './package.json'
const isProd = process.env.NODE_ENV === 'production'
const formats = {
commonjs: {
format: 'cjs',
file: pkg.main,
exports: 'named'
},
esm: {
format: 'esm',
file: pkg.module,
exports: 'named'
},
umd: {
format: 'umd',
name: snakeCase(parsePackageName(pkg.name).name),
exports: 'named',
globals: {}
}
}
const config = {
input: './src/index.ts',
inlineDynamicImports: true,
output: [formats.esm, formats.commonjs],
plugins: [
clear({
targets: ['dist']
}),
progress({
clearLine: false
}),
replace({
__VERSION__: pkg.version,
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
}),
externals({
deps: true
}),
nodeResolver(),
commonjs(),
typescript(),
json()
],
watch: {
include: 'src/**',
exclude: 'node_modules/**'
}
}
if (isProd) {
const file = formats.commonjs.file
const ext = extname(file)
config.output.push({
...formats.umd,
file: join(dirname(file), `${basename(file, ext)}.umd${ext}`),
plugins: [filesize()]
})
config.output.push({
...formats.umd,
file: join(dirname(file), `${basename(file, ext)}.umd.min${ext}`),
plugins: [terser()]
})
config.plugins.push(
visualizer({
title: `${pkg.name} - ${pkg.author.name}`,
filename: 'dist/bundle-analyzer-report.html'
})
)
}
export default config