-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
105 lines (89 loc) · 1.92 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
101
102
103
104
105
// 根据 tsconfig.json 把 ts 转成 js
import typescript from 'rollup-plugin-typescript2'
// 替换代码中的变量
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 { name, version, author, license } from './package.json'
const moduleName = name.split('/').pop()
const startYear = 2021
const currentYear = new Date().getFullYear()
const yearRange = [currentYear]
if (startYear != currentYear) {
yearRange.unshift(startYear)
}
const banner =
`${'/**\n' + ' * '}${moduleName}.js v${version}\n` +
` * (c) ${yearRange.join('-')} ${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 replaces = {
'process.env.NODE_ENV': JSON.stringify(env),
'process.env.NODE_VERSION': JSON.stringify(version),
preventAssignment: true
}
let plugins = [
replace(replaces),
]
if (minify) {
suffix = '.min' + suffix
}
const output = []
if (process.env.NODE_FORMAT === 'es') {
plugins.push(
typescript({
check: false,
useTsconfigDeclarationDir: true
})
)
output.push({
file: `dist/${moduleName}.esm${suffix}`,
format: 'es',
interop: false,
banner,
sourcemap,
})
}
else {
plugins.push(
typescript({
check: false,
useTsconfigDeclarationDir: true
}),
buble({
namedFunctionExpressions: false
})
)
output.push({
file: `dist/${moduleName}${suffix}`,
format: 'umd',
name: 'Url',
interop: false,
banner,
sourcemap,
})
}
if (minify) {
plugins.push(
terser()
)
}
plugins.push(
filesize(),
)
module.exports = [
{
input: 'src/index.ts',
external: ['url'],
output,
plugins
}
]