-
Notifications
You must be signed in to change notification settings - Fork 55
/
rollup.config.service-worker.js
58 lines (55 loc) · 1.56 KB
/
rollup.config.service-worker.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
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import resolve from '@rollup/plugin-node-resolve';
import * as fs from 'fs';
import {maybeTerser} from './rollup.config.common.js';
/**
* Rollup plugin which generates an HTML file with all input JavaScript
* bundles inlined into script tags.
*/
function inlineHtml(htmlOutPath) {
return {
name: 'inline-html',
generateBundle: async (_outputOptions, bundles, isWrite) => {
if (!isWrite) {
return;
}
const scripts = [];
for (const [name, bundle] of Object.entries(bundles)) {
scripts.push(`<script type="module">${bundle.code.trim()}</script>`);
// Don't emit the input bundle as its own file.
delete bundles[name];
}
const html = `<!doctype html>${scripts.join('')}`;
await fs.promises.writeFile(htmlOutPath, html, 'utf8');
},
};
}
export default [
// Generate playground-service-worker-proxy.html, the HTML file + inline
// script that proxies between a project and a service worker on a possibly
// different origin.
{
input: 'playground-service-worker-proxy.js',
output: {
file: 'playground-service-worker-proxy-temp-bundle.js',
format: 'esm',
},
plugins: [
...maybeTerser,
inlineHtml('playground-service-worker-proxy.html'),
],
},
{
input: 'service-worker/playground-service-worker.js',
output: {
file: 'playground-service-worker.js',
format: 'iife',
exports: 'none',
},
plugins: [resolve(), ...maybeTerser],
}
];