forked from jakearchibald/idb-keyval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
162 lines (155 loc) · 3.77 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { promises as fsp } from 'fs';
import { basename } from 'path';
import { promisify } from 'util';
import simpleTS from './lib/simple-ts';
import del from 'del';
import { terser } from 'rollup-plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import babel, { getBabelOutputPlugin } from '@rollup/plugin-babel';
import glob from 'glob';
const globP = promisify(glob);
function removeDefs() {
return {
generateBundle(_, bundle) {
for (const key of Object.keys(bundle)) {
if (key.includes('.d.ts')) delete bundle[key];
}
},
};
}
const babelPreset = [['@babel/preset-env', { targets: { ie: '10' } }]];
function getBabelPlugin() {
return getBabelOutputPlugin({
presets: babelPreset,
allowAllFormats: true,
});
}
export default async function ({ watch }) {
const devBuild = watch;
await del('dist');
if (devBuild)
return {
input: 'test/index.ts',
plugins: [
simpleTS('test', { watch }),
commonjs(),
// When testing IE10
// babel({
// presets: babelPreset,
// babelHelpers: 'runtime',
// extensions: ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts'],
// plugins: [
// [
// '@babel/plugin-transform-runtime',
// {
// useESModules: true,
// },
// ],
// ],
// exclude: /node_modules/,
// }),
resolve(),
// Copy HTML file
{
async generateBundle() {
this.emitFile({
type: 'asset',
source: await fsp.readFile(`test/index.html`),
fileName: 'index.html',
});
},
},
],
output: [
{
file: 'dist/test/index.js',
format: 'es',
},
],
watch: {
clearScreen: false,
// Don't watch the ts files. Instead we watch the output from the ts compiler.
exclude: ['**/*.ts', '**/*.tsx'],
},
};
return [
// Main builds
{
input: 'src/index.ts',
plugins: [simpleTS('src')],
output: [
{
file: 'dist/esm/index.js',
format: 'es',
},
{
file: 'dist/cjs/index.js',
format: 'cjs',
},
{
file: 'dist/iife/index-min.js',
format: 'iife',
name: 'idbKeyval',
esModule: false,
plugins: [
terser({
compress: { ecma: 2020 },
}),
removeDefs(),
],
},
],
},
// Compat builds
{
input: 'src/index.ts',
external: (id) => {
if (id.startsWith('@babel/runtime')) return true;
},
plugins: [simpleTS('src', { noBuild: true })],
output: [
{
file: 'dist/esm-compat/index.js',
format: 'es',
plugins: [getBabelPlugin()],
},
{
file: 'dist/cjs-compat/index.js',
format: 'cjs',
plugins: [getBabelPlugin()],
},
{
file: 'dist/iife-compat/index-min.js',
format: 'iife',
name: 'idbKeyval',
esModule: false,
plugins: [
getBabelPlugin(),
terser({
compress: { ecma: 5 },
}),
removeDefs(),
],
},
],
},
// Size tests
...(await globP('size-tests/*.js').then((paths) =>
paths.map((path) => ({
input: path,
plugins: [
terser({
compress: { ecma: 2020 },
}),
],
output: [
{
file: `dist/size-tests/${basename(path)}`,
format: 'es',
},
],
})),
)),
];
}