-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
100 lines (88 loc) · 2.1 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { join } from 'path'
import camelCase from 'lodash/camelCase'
import buble from 'rollup-plugin-buble'
import commonjs from 'rollup-plugin-commonjs'
import resolve from 'rollup-plugin-node-resolve'
import clear from 'rollup-plugin-clear'
import { eslint } from 'rollup-plugin-eslint'
import filesize from 'rollup-plugin-filesize'
import json from 'rollup-plugin-json'
import progress from 'rollup-plugin-progress'
import replace from 'rollup-plugin-replace'
import {
name,
version,
author,
license,
peerDependencies,
optionalDependencies
} from './package.json'
process.env.NODE_ENV = 'production'
// 处理路径
const toPath = (...paths) => join(__dirname, ...paths)
// 默认对 js 进行压缩输出
// const isMinify = (v => v === undefined || v)(process.env.npm_config_minify)
const env = {
__VERSION__: version,
NODE_ENV: process.env.NODE_ENV
}
const banner =
`/**
* ${name} v${version}
*
* (c) ${new Date().getFullYear()} ${author}
*
* @author ${author}
* @license ${license}
*/`
const configs = {
cjs: {
input: 'src/index.js',
output: `dist/lib.common.js`
},
es: {
input: 'src/index.js',
output: `dist/lib.esm.js`
}
}
const depends = Object.keys(Object.assign({}, peerDependencies, optionalDependencies))
const genConfig = ({ input, output, plugins = [] }, format) => {
return {
input: toPath(input),
output: {
banner,
name: camelCase(name.replace(/^@.+\//, '')),
file: toPath(output),
format
},
external (path) {
return depends.some(name => {
return path.indexOf(name) > -1
})
},
plugins: [
clear({
targets: [
'dist',
'bundle-analyzer-report.html'
]
}),
progress({
clearLine: false
}),
eslint(),
replace(Object.keys(env).reduce((obj, key) => {
obj[key] = JSON.stringify(env[key])
return obj
}, {})),
resolve(),
commonjs(),
json(),
buble(),
filesize()
].concat(plugins || [])
}
}
export default Object.keys(configs).map(key => {
return genConfig(configs[key], key)
})