-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
87 lines (67 loc) · 1.65 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
import path from 'path'
import typescript from 'rollup-plugin-typescript2'
const { terser } = require('rollup-plugin-terser')
import nodeResolve from '@rollup/plugin-node-resolve'
const OUTPUT_CJS = 'cjs';
const OUTPUT_IIFE = 'iife';
const OUTPUT_ES = 'es';
const OUTPUT_UMD = 'umd';
const name = 'tinydb'
const entryFile = './src/core/index.ts'
const outputConfigs = {
[OUTPUT_UMD]: {
file: path.resolve(`dist/${name}.umd.js`),
format: OUTPUT_UMD
},
[OUTPUT_ES]: {
file: path.resolve(`dist/${name}.es.js`),
format: OUTPUT_ES
},
[OUTPUT_IIFE]: {
file: path.resolve(`dist/${name}.global.js`),
format: OUTPUT_IIFE
},
[OUTPUT_CJS]: {
file: path.resolve(`dist/${name}.cjs.js`),
format: OUTPUT_CJS,
}
}
const defaultFormats = [OUTPUT_CJS, OUTPUT_ES, OUTPUT_IIFE]
const packageConfigs = defaultFormats.map( format => createConfig(format, outputConfigs[format]))
export default packageConfigs;
function createConfig(format, output, plugins = []) {
if (!output) {
console.log(chalk.yellow(`invalid format: "${format}"`))
process.exit(1)
}
if(format === 'iife') {
output.name = 'DB'
}
const extensions = ['.ts']
const noDeclaration = false
const tsProject = typescript({
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
declaration: noDeclaration
}
}
})
return {
input: entryFile,
plugins: [
nodeResolve({
extensions
}),
tsProject,
terser({
compress: {
ecma: 2015,
pure_getters: true,
}
}),
...plugins,
],
output
}
}