-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
99 lines (85 loc) · 1.69 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
// 根据 tsconfig.json 把 ts 转成 js
import typescript from 'rollup-plugin-typescript'
// 替换代码中的变量
import replace from 'rollup-plugin-replace'
// 输出打包后的文件大小
import filesize from 'rollup-plugin-filesize'
// ES6 转 ES5
import buble from 'rollup-plugin-buble'
// 压缩
import { terser } from 'rollup-plugin-terser'
// 本地服务器
import serve from 'rollup-plugin-serve'
import { name, version, author, license } from './package.json'
const banner =
`${'/**\n' + ' * '}${name}.js v${version}\n` +
` * (c) 2017-${new Date().getFullYear()} ${author}\n` +
` * Released under the ${license} License.\n` +
` */\n`;
const sourcemap = true
let suffix = '.js'
const env = process.env.NODE_ENV
const minify = process.env.NODE_MINIFY === 'true'
const port = process.env.NODE_PORT
const replaces = {
'process.env.NODE_ENV': JSON.stringify(env),
'process.env.NODE_VERSION': JSON.stringify(version)
}
let plugins = [
replace(replaces)
]
if (minify) {
suffix = '.min' + suffix
}
const output = []
if (process.env.NODE_FORMAT === 'es') {
plugins.push(
typescript({
target: 'es6'
})
)
output.push({
file: `dist/${name}.esm${suffix}`,
format: 'es',
banner,
sourcemap,
})
}
else {
plugins.push(
typescript(),
buble({
namedFunctionExpressions: false
})
)
output.push({
file: `dist/${name}${suffix}`,
format: 'umd',
name: 'Soga',
banner,
sourcemap,
})
}
if (minify) {
plugins.push(
terser()
)
}
plugins.push(
filesize()
)
if (port) {
plugins.push(
serve({
port,
contentBase: ['']
})
)
}
module.exports = [
{
input: 'index.ts',
output,
plugins
}
]