-
Notifications
You must be signed in to change notification settings - Fork 257
/
rollup.config.ts
89 lines (80 loc) · 2.24 KB
/
rollup.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
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
import ts from '@rollup/plugin-typescript'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import pkg from './package.json'
const banner = `
/**
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} Lachlan Miller
* Released under the MIT License
*/
`
function createEntry(options) {
const { format, input, isBrowser } = options
const isEsmBrowser = format === 'es' && isBrowser
const config = {
input,
external: [
'vue',
isEsmBrowser
? '@vue/compiler-dom/dist/compiler-dom.esm-browser'
: '@vue/compiler-dom',
isEsmBrowser
? '@vue/server-renderer/dist/compiler-dom.esm-browser'
: '@vue/server-renderer'
],
plugins: [
replace({
values: {
'process.env.NODE_ENV': 'true',
__BROWSER__: isEsmBrowser,
__USE_PREFIX_IDENTIFIERS__: isEsmBrowser || format === 'cjs'
},
preventAssignment: true
}),
resolve(),
commonjs(),
json()
],
output: {
banner,
name: 'VueTestUtils',
file: 'dist/vue-test-utils.browser.js',
format,
globals: {
vue: 'Vue',
'@vue/compiler-dom': 'VueCompilerDOM',
'@vue/server-renderer': 'VueServerRenderer'
}
}
}
if (format === 'es') {
config.output.file = pkg.module
if (isBrowser) {
config.output.file = 'dist/vue-test-utils.esm-browser.js'
}
}
if (format === 'cjs') {
config.output.file = pkg.main
}
console.log(`Building ${format}: ${config.output.file}`)
config.plugins.push(
ts({
include: ['src/**/*.ts', 'types/**/*.d.ts'],
compilerOptions: {
declaration: format === 'es',
target: 'es5', // not sure what this should be?
module: format === 'cjs' ? 'es2015' : 'esnext'
}
})
)
return config
}
export default [
createEntry({ format: 'es', input: 'src/index.ts', isBrowser: false }),
createEntry({ format: 'es', input: 'src/index.ts', isBrowser: true }),
createEntry({ format: 'iife', input: 'src/index.ts', isBrowser: true }),
createEntry({ format: 'cjs', input: 'src/index.ts', isBrowser: false })
]