-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
109 lines (106 loc) · 2.61 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
/* eslint-env node */
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import html from '@web/rollup-plugin-html';
import fs from 'fs';
import copy from 'rollup-plugin-copy';
import livereload from 'rollup-plugin-livereload';
import replace from 'rollup-plugin-re';
import { generateSW } from 'rollup-plugin-workbox';
import { compileBufferTemplate, compileTemplate, production } from './build-utils';
import { workboxConfig } from './workbox-config';
import { terser } from 'rollup-plugin-terser';
const { ROLLUP_WATCH } = process.env;
export default [
{
input: 'firebase-messaging-sw.ts',
treeshake: production,
output: {
file: 'dist/firebase-messaging-sw.js',
sourcemap: true,
},
plugins: [
nodeResolve(),
typescript({
noEmitOnError: true,
}),
production && terser(),
],
},
{
treeshake: production,
output: {
dir: 'dist',
entryFileNames: '[name]-[hash].js',
sourcemap: true,
},
plugins: [
nodeResolve(),
typescript({
noEmitOnError: true,
}),
html({
input: {
html: compileBufferTemplate(fs.readFileSync('index.html')),
},
extractAssets: false,
minify: production,
transformHtml: [
(html) => {
return compileTemplate(html);
},
],
transformAsset: [
(content, path) => {
if (path.endsWith('.json')) {
return compileBufferTemplate(content);
}
return content;
},
],
}),
replace({
exclude: 'node_modules/**',
patterns: [
{
transform: (code, path) => {
if (path.endsWith('.ts')) {
return compileTemplate(code);
}
return code;
},
},
],
}),
copy({
targets: [
{
src: 'manifest.json',
dest: 'dist',
transform: compileBufferTemplate,
},
{
src: 'images',
dest: 'dist',
},
{
src: 'data/*.md',
dest: 'dist/data',
transform: compileBufferTemplate,
},
{
src: 'data/posts/*.md',
dest: 'dist/data/posts',
transform: compileBufferTemplate,
},
],
}),
production && generateSW(workboxConfig),
production && terser(),
ROLLUP_WATCH &&
livereload({
watch: 'dist',
}),
],
},
];