-
Notifications
You must be signed in to change notification settings - Fork 73
/
rollup.plugins.config.ts
58 lines (55 loc) · 1.66 KB
/
rollup.plugins.config.ts
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
import { nodeResolve } from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import { generateSW } from 'rollup-plugin-workbox';
import terser from '@rollup/plugin-terser';
import { glob } from 'glob';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
//import babel from 'rollup-plugin-babel'; // To support legacy browsers. Disabled by default.
const plugins = (outDir) => [
nodeResolve(),
typescript({
tsconfig: "./tsconfig.json",
outDir: outDir
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true
}),
terser(),
generateSW( {
swDest: 'build/rollup/sw.js',
globDirectory: 'build/rollup/',
globPatterns: [
'dist/**/*.{html,json,js,css}',
'src/lib/**/*.{js, map}'
],
skipWaiting: true,
})
// babel()
];
export default [
{
// ref: https://rollupjs.org/configuration-options/#input
input: Object.fromEntries(
glob.sync('src/plugins/**/*.ts').map(file => [
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
'src/plugins',
file.slice(0, file.length - path.extname(file).length)
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url))
])
),
output: {
dir: 'build/rollup/dist/plugins',
format: 'es',
sourcemap: false
},
plugins: plugins('build/rollup/dist/plugins')
}
];