-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
52 lines (45 loc) · 1.5 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
// @ts-check
import { readFileSync } from 'fs';
import commonjs from '@rollup/plugin-commonjs';
import consts from 'rollup-plugin-consts';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import typescript from '@rollup/plugin-typescript';
const commitHash = () => {
try {
return readFileSync('.commithash', 'utf-8').trim();
} catch (_) {
return 'unknown';
}
};
/** @type {import('rollup').OptionsPaths} */
const paths = {
'node-vibrant': '../lib/node-vibrant/vibrant.js',
'insights-js': '../lib/insights.js',
};
const worker_url = 'js/db-worker.js';
/** @type {import('rollup').RollupOptions} */
const pageConfig = {
input: 'src/page/index.ts',
output: {
dir: 'public/js/',
format: 'esm',
sourcemap: true,
paths,
},
external: Object.keys(paths),
plugins: [typescript(), resolve(), consts({ worker_url }), terser()],
};
/** @type {import('rollup').RollupOptions} */
const workerConfig = {
input: 'src/db-worker/index.ts',
output: { file: `public/${worker_url}`, format: 'esm', sourcemap: true },
plugins: [typescript(), resolve(), commonjs(), terser()],
};
/** @type {import('rollup').RollupOptions} */
const serviceWorkerConfig = {
input: 'src/service-worker/index.ts',
output: { file: 'public/sw.js', format: 'esm', sourcemap: true },
plugins: [typescript(), consts({ hash: commitHash }), terser()],
};
export default [pageConfig, workerConfig, serviceWorkerConfig];