forked from vuejs/composition-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
112 lines (104 loc) · 2.57 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
106
107
108
109
110
111
112
import * as path from 'path'
import typescript from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve'
import { terser } from 'rollup-plugin-terser'
import replace from '@rollup/plugin-replace'
import dts from 'rollup-plugin-dts'
import { version } from './package.json'
const builds = {
'cjs-dev': {
outFile: 'vue-composition-api.common.js',
format: 'cjs',
mode: 'development',
},
'cjs-prod': {
outFile: 'vue-composition-api.common.prod.js',
format: 'cjs',
mode: 'production',
},
'umd-dev': {
outFile: 'vue-composition-api.js',
format: 'umd',
mode: 'development',
},
'umd-prod': {
outFile: 'vue-composition-api.prod.js',
format: 'umd',
mode: 'production',
},
esm: {
outFile: 'vue-composition-api.esm.js',
format: 'es',
mode: 'development',
},
}
function onwarn(msg, warn) {
if (!/Circular/.test(msg)) {
warn(msg)
}
}
function getAllBuilds() {
return Object.keys(builds).map((key) => genConfig(builds[key]))
}
function genConfig({ outFile, format, mode }) {
const isProd = mode === 'production'
return {
input: './src/index.ts',
output: {
file: path.join('./dist', outFile),
format: format,
globals: {
vue: 'Vue',
},
exports: 'named',
name: format === 'umd' ? 'VueCompositionAPI' : undefined,
},
external: ['vue'],
onwarn,
plugins: [
typescript({
tsconfigOverride: {
declaration: false,
declarationDir: null,
emitDeclarationOnly: false,
},
useTsconfigDeclarationDir: true,
}),
resolve(),
replace({
preventAssignment: true,
'process.env.NODE_ENV':
format === 'es'
? // preserve to be handled by bundlers
'process.env.NODE_ENV'
: // hard coded dev/prod builds
JSON.stringify(isProd ? 'production' : 'development'),
__DEV__:
format === 'es'
? // preserve to be handled by bundlers
`(process.env.NODE_ENV !== 'production')`
: // hard coded dev/prod builds
!isProd,
__VERSION__: JSON.stringify(version),
}),
isProd && terser(),
].filter(Boolean),
}
}
let buildConfig
if (process.env.TARGET) {
buildConfig = [genConfig(builds[process.env.TARGET])]
} else {
buildConfig = getAllBuilds()
}
// bundle typings
buildConfig.push({
input: 'typings/index.d.ts',
output: {
file: 'dist/index.d.ts',
format: 'es',
},
onwarn,
plugins: [dts()],
})
export default buildConfig