-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cdn.js
47 lines (43 loc) · 1.33 KB
/
build.cdn.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
import esbuild from "esbuild";
import { readFile } from 'node:fs/promises';
//import info from "./package.json" assert { type: "json" };
//const externals = Object.keys(info.peerDependencies);
esbuild.build({
entryNames: "[dir]/[name]",
bundle: true,
minify: true,
splitting: true,
format: "esm",
entryPoints: [
"./src/lit-line.ts",
],
outdir: "cdn",
plugins: [],
external: [], // empty to ensure deps are bundled
});
/*
* From the awesome bennypowers/lit-css
*/
export function minifyHTMLLiteralsPlugin(options) {
const { filter = /\.[jt]s$/, ...minifyOptions } = options ?? {};
return {
name: 'minifyHTMLLiterals',
setup(build) {
const cache = new Map();
build.onLoad({ filter }, async ({ path }) => {
const loader = path.match(/c?tsx?$/) ? 'ts' : 'js';
const input = await readFile(path, 'utf8');
const cached = cache.get(path);
if (cached?.source === input)
return cached.output;
else {
const result = minifyHTMLLiterals(input, minifyOptions) ?? undefined;
const contents = result && `${result.code}\n//# sourceMappingURL=${result.map?.toUrl()}`;
const output = result && { contents, loader };
cache.set(path, { input, output });
return output;
}
});
},
};
}