-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
77 lines (71 loc) · 1.86 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
const babel = require('rollup-plugin-babel')
const commonjs = require('rollup-plugin-commonjs')
const replace = require('rollup-plugin-replace')
const resolve = require('rollup-plugin-node-resolve')
const json = require('rollup-plugin-json')
const { uglify } = require('rollup-plugin-uglify')
const { startCase } = require('lodash')
const PKG = require('./package.json')
function configure(env, target) {
const isProd = env === 'production'
const isUmd = target === 'umd'
const isModule = target === 'module'
const input = `src/index.js`
const deps = []
.concat(PKG.dependencies ? Object.keys(PKG.dependencies) : [])
.concat(PKG.peerDependencies ? Object.keys(PKG.peerDependencies) : [])
const plugins = [
resolve({
// browser: true
}),
commonjs(),
json(),
replace({
'process.env.NODE_ENV': JSON.stringify(env)
}),
babel({
include: [`src/**`],
presets: [['env', { modules: false }]]
}),
isUmd && isProd && uglify()
].filter(Boolean)
if (isUmd) {
return {
plugins,
input,
output: {
format: 'umd',
file: isProd
? 'dist/analytics-event.min.js'
: 'dist/analytics-event.js',
name: startCase(PKG.name).replace(/ /g, '')
}
}
}
if (isModule) {
return {
plugins,
input,
output: [
{
file: PKG.module,
format: 'es',
sourcemap: true
},
{
file: PKG.main,
format: 'cjs',
sourcemap: true
}
],
external: id => {
return !!deps.find(dep => dep === id || id.startsWith(`${dep}/`))
}
}
}
}
export default [
configure('development', 'module'),
process.env.NODE_ENV === 'production' && configure('development', 'umd'),
process.env.NODE_ENV === 'production' && configure('production', 'umd')
].filter(Boolean)