forked from vuejs/vuefire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
125 lines (111 loc) · 3.16 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
113
114
115
116
117
118
119
120
121
122
123
124
125
import replace from '@rollup/plugin-replace'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import ts from 'rollup-plugin-typescript2'
import alias from '@rollup/plugin-alias'
import stripBanner from 'rollup-plugin-strip-banner'
import { terser } from 'rollup-plugin-terser'
import path from 'path'
import rimraf from 'rimraf'
const cwd = process.cwd()
// eslint-disable-next-line
const pkg = require(path.join(cwd, 'package.json'))
rimraf.sync(path.join(cwd, './dist'))
const banner = `/*!
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} Eduardo San Martin Morote
* @license MIT
*/`
const firstLetter = pkg.name[0]
const exportName =
firstLetter !== '@' ? firstLetter.toUpperCase() + pkg.name.slice(1) : 'VuefireCore'
function createEntry(
{
format, // Rollup format (iife, umd, cjs, es)
external, // Rollup external option
input = 'src/index.ts', // entry point
env = 'development', // NODE_ENV variable
minify = false,
isBrowser = false, // produce a browser module version or not
} = {
input: 'src/index.ts',
env: 'development',
minify: false,
isBrowser: false,
}
) {
// force production mode when minifying
if (minify) env = 'production'
const config = {
input,
plugins: [
replace({
__VERSION__: pkg.version,
'process.env.NODE_ENV': `'${env}'`,
}),
alias({
resolve: ['.ts', '.js'],
entries: [{ find: 'firebase', replacement: path.join(__dirname, './stub') }],
}),
],
output: {
banner,
file: `dist/${pkg.name}.UNKNOWN.js`,
format,
},
}
if (format === 'iife') {
config.output.file = pkg.unpkg
config.output.name = exportName
} else if (format === 'es') {
config.output.file = isBrowser ? pkg.browser : pkg.module
} else if (format === 'cjs') {
config.output.file = pkg.main
}
if (!external) {
config.plugins.push(
resolve(),
commonjs(),
// avoid duplicated banners when reusing packages
stripBanner({
include: path.join(__dirname, './packages/**/*.js'),
})
)
} else {
config.external = external
}
config.plugins.push(
ts({
// only check once, during the es version with browser (it includes external libs)
check: format === 'es' && isBrowser && !minify,
tsconfigOverride: {
exclude: ['__tests__'],
compilerOptions: {
// same for d.ts files
declaration: format === 'es' && isBrowser && !minify,
target: format === 'es' && !isBrowser ? 'esnext' : 'es5',
},
},
})
)
if (minify) {
config.plugins.push(
terser({
module: format === 'es',
output: {
preamble: banner,
},
})
)
config.output.file = config.output.file.replace(/\.js$/i, '.min.js')
}
return config
}
const builds = [createEntry({ format: 'cjs' }), createEntry({ format: 'es', isBrowser: true })]
if (pkg.unpkg)
builds.push(
createEntry({ format: 'iife' }),
createEntry({ format: 'iife', minify: true }),
createEntry({ format: 'es', isBrowser: true, minify: true })
)
export default builds