-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.sw.config.js
41 lines (38 loc) · 1.06 KB
/
rollup.sw.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
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import fs from 'fs'
const dist = fs.readdirSync('./dist').filter(file => /(?<!(swfiles|service-worker))\.js$/.test(file)).map(f => `"/dist/${f}"\n`)
const style = fs.readdirSync('./styles').filter(file => /\.css$/.test(file)).map(f => `"/styles/${f}"\n`)
const files = dist.concat(style)
fs.writeFileSync('./dist/swfiles.js', `export const precache = [${files.join(',')}]`)
const minificationPlugins = process.env.PRODUCTION ? [terser({
module: true,
compress: {
hoist_vars: true,
module: true,
passes: 1,
pure_getters: true,
unsafe_comps: true,
unsafe_undefined: true
},
mangle: {
toplevel: true
}
})] : []
export default [{
input: './src/service-worker.js',
output: [{
dir: './',
format: 'iife',
sourcemap: true
}],
plugins: [
nodeResolve({
sourcemap: true,
mainFields: ['module', 'browser', 'main']
}),
commonjs(),
...minificationPlugins
]
}]