forked from open-wc/open-wc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli-build.js
88 lines (75 loc) · 2.15 KB
/
cli-build.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
/* eslint-disable */
const path = require('path');
const copy = require('rollup-plugin-copy');
const { rollup } = require('rollup');
const { generateSW } = require('rollup-plugin-workbox');
const Eleventy = require('@11ty/eleventy');
const { createMpaConfig } = require('./docs/_building-rollup/createMpaConfig.js');
const elev = new Eleventy('./docs', './_site');
elev.setConfigPathOverride('./docs/.eleventy.js');
elev.setDryRun(true); // do not write to file system
/**
* @param {object} config
*/
async function buildAndWrite(config) {
const bundle = await rollup(config);
if (Array.isArray(config.output)) {
await bundle.write(config.output[0]);
await bundle.write(config.output[1]);
} else {
await bundle.write(config.output);
}
}
async function productionBuild(html) {
const mpaConfig = createMpaConfig({
outputDir: '_site',
legacyBuild: false,
html: { html },
injectServiceWorker: false,
workbox: false,
});
mpaConfig.plugins.push(
generateSW({
globIgnores: ['polyfills/*.js', 'legacy-*.js', 'nomodule-*.js'],
swDest: path.join(process.cwd(), '_site', 'service-worker.js'),
globDirectory: path.join(process.cwd(), '_site'),
globPatterns: ['**/*.{html,js,json,css,webmanifest,png,gif}'],
skipWaiting: true,
clientsClaim: true,
runtimeCaching: [
{
urlPattern: 'polyfills/*.js',
handler: 'CacheFirst',
},
],
}),
);
const dest = '_site/';
mpaConfig.plugins.push(
copy({
targets: [
{ src: 'docs/styles.css', dest },
{ src: 'docs/demoing/demo/custom-elements.json', dest },
{ src: 'docs/manifest.json', dest },
{ src: 'docs/**/*.{png,gif}', dest },
],
flatten: false,
}),
);
await buildAndWrite(mpaConfig);
}
async function main() {
const htmlFiles = [];
elev.config.filters['hook-for-rocket'] = (html, outputPath, inputPath) => {
htmlFiles.push({
html,
name: outputPath.substring(8),
rootDir: path.dirname(path.resolve(inputPath)),
});
return html;
};
await elev.init();
await elev.write();
await productionBuild(htmlFiles);
}
main();