-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
build.config.ts
64 lines (56 loc) · 1.49 KB
/
build.config.ts
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
import { defineBuildConfig } from 'unbuild'
import type { PackageJson } from 'pkg-types'
export default defineBuildConfig({
entries: ['./src/index'],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
},
hooks: {
'rollup:options'(ctx, options) {
// in reality the output is always an array
options.output = options.output
? Array.isArray(options.output)
? options.output
: [options.output]
: []
options.output.push({
name: 'VueGlobalEvents',
dir: './dist',
format: 'iife',
globals: {
'vue-demi': 'VueDemi',
vue: 'Vue',
},
exports: 'auto',
freeze: false,
externalLiveBindings: false,
})
// add the banner
const banner = getBanner(ctx.pkg)
for (const output of options.output) {
output.banner = banner
}
},
},
})
function getAuthors(pkg: PackageJson) {
const { contributors, author } = pkg
const authors = new Set()
if (contributors && contributors)
contributors.forEach((contributor) => {
authors.add(
typeof contributor === 'string' ? contributor : contributor.name
)
})
if (author) authors.add(typeof author === 'string' ? author : author.name)
return Array.from(authors).join(', ')
}
function getBanner(pkg: PackageJson) {
return `/*!
* ${pkg.name} v${pkg.version}
* (c) 2019-${new Date().getFullYear()} ${getAuthors(pkg)}
* Released under the MIT License.
*/`
}