-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathrollup.config.js
83 lines (79 loc) · 2.35 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
import {flatMap, compact} from 'lodash'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import babel from 'rollup-plugin-babel'
import {terser} from 'rollup-plugin-terser'
import license from 'rollup-plugin-license'
import pkg from './package.json'
const banner = `
<%= pkg.name %> <%= pkg.version %>
MIT Licensed
Generated by <%= pkg.authors[0] %>
Generated at <%= moment().format('YYYY-MM-DD') %>
`
export default flatMap(['none', 'shouldMinify', 'noClassesTranspile', 'both'], buildMode => {
const shouldMinify = buildMode === 'shouldMinify' || buildMode === 'both'
const shouldTranspileClasses = buildMode === 'none' || buildMode === 'both'
const babelPlugins = compact([
shouldTranspileClasses && '@babel/plugin-transform-classes'
])
return [
{
input: 'src/index.js',
output: {
name: 'whyDidYouRender',
file: (shouldTranspileClasses ? pkg.browser : pkg['browser-no-classes-transpile'])
.replace('.min', shouldMinify ? '.min' : ''),
format: 'umd',
sourcemap: shouldMinify,
sourcemapFile: pkg.browser.replace('.js', '.js.map')
},
plugins: [
babel({
exclude: 'node_modules/**',
plugins: babelPlugins
}),
resolve(),
commonjs(),
shouldMinify && terser(),
license({
sourcemap: true,
banner
})
]
},
{
input: 'src/index.js',
output: [
{
file: (shouldTranspileClasses ? pkg.main : pkg['main-no-classes-transpile'])
.replace('.min', shouldMinify ? '.min' : ''),
format: 'cjs',
sourcemap: shouldMinify,
sourcemapFile: pkg.main.replace('.js', '.js.map')
},
{
file: (shouldTranspileClasses ? pkg.module : pkg['module-no-classes-transpile'])
.replace('.min', shouldMinify ? '.min' : ''),
format: 'esm',
sourcemap: shouldMinify,
sourcemapFile: pkg.module.replace('.js', '.js.map')
}
],
plugins: [
babel({
exclude: 'node_modules/**',
plugins: babelPlugins
}),
resolve(),
commonjs(),
shouldMinify && terser(),
license({
sourcemap: true,
banner
})
],
external: id => /lodash/.test(id)
}
]
})