forked from kevdonk/devsummit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
78 lines (73 loc) · 2.35 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
import { promises as fsp } from 'fs';
import { terser } from 'rollup-plugin-terser';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import htmlCSSPlugin from './lib/html-css-plugin.js';
import postCSSBuild from './lib/postcss-build.js';
import eleventyPlugin from './lib/11ty-plugin.js';
import globInputPlugin from './lib/glob-input-plugin';
import httpServer from './lib/http-server';
import buildStartSequencePlugin from './lib/build-start-sequence-plugin';
import classnamePlugin from './lib/classname-plugin';
import assetPlugin from './lib/asset-plugin';
import confboxConfigPlugin from './lib/confbox-config-plugin';
import swPlugin from './lib/sw-plugin';
import copy from './lib/copy';
const confboxConfig = require('./confbox.config.js');
export default async function({ watch }) {
await Promise.all([postCSSBuild('src/**/*.css', '.build-tmp', { watch })]);
if (watch) {
httpServer();
}
return {
input: {
'nuke-sw': 'src/nuke-sw.js',
sw: 'src/sw.js',
},
output: {
dir: 'build' + confboxConfig.path,
format: 'esm',
assetFileNames: '[name]-[hash][extname]',
},
watch: {
clearScreen: false,
// Avoid watching intermediate files, else watch gets stuck in a loop.
// 11ty source files are watched by eleventyPlugin.
exclude: '.build-tmp/**/*.html',
},
plugins: [
nodeResolve(),
commonjs(),
{
resolveFileUrl({ fileName }) {
return JSON.stringify(confboxConfig.path + fileName);
},
},
buildStartSequencePlugin(),
eleventyPlugin(),
globInputPlugin('.build-tmp/**/*.html'),
htmlCSSPlugin(),
assetPlugin(),
classnamePlugin('.build-tmp'),
confboxConfigPlugin(),
terser({ ecma: 8, module: true }),
copy({
'.build-tmp/**/*.ics': {
stripPrefix: '.build-tmp/',
dest: '.',
},
}),
swPlugin(),
{
// This is a dirty hack to copy /devsummit/404.html to /404.html, which is where
// Firebase hosting will look for the 404 page.
async writeBundle(bundle) {
const notFound = Object.values(bundle).find(entry =>
entry.fileName.endsWith('404.html'),
);
await fsp.writeFile('build/404.html', notFound.code);
},
},
],
};
}