MCPcopy
hub / github.com/highlightjs/highlight.js / buildCDN

Function buildCDN

tools/build_cdn.js:31–96  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

29let shas = {};
30
31async function buildCDN(options) {
32 install("./LICENSE", "LICENSE");
33 install("./README.CDN.md", "README.md");
34 await installPackageJSON(options);
35
36 installStyles();
37
38 // all the languages are built for the CDN and placed into `/languages`
39 const languages = await getLanguages();
40
41 let esmCoreSize = {};
42 let esmCommonSize = {};
43
44 await installLanguages(languages, options);
45
46 // filter languages for inclusion in the highlight.js bundle
47 let embedLanguages = filter(languages, options.languages);
48
49 // it really makes no sense to embed ALL languages with the CDN build, it's
50 // more likely we want to embed NONE and have completely separate run-time
51 // loading of some sort
52 if (embedLanguages.length === languages.length) {
53 embedLanguages = [];
54 }
55
56 const size = await buildCore("highlight", embedLanguages, { minify: options.minify, format: "cjs" });
57 if (options.esm) {
58 mkdir("es");
59 await fs.writeFile(`${process.env.BUILD_DIR}/es/package.json`, `{ "type": "module" }`);
60 esmCoreSize = await buildCore("core", [], { minify: options.minify, format: "es" });
61 esmCommonSize = await buildCore("highlight", embedLanguages, { minify: options.minify, format: "es" });
62 }
63 shas = {
64 ...size.shas, ...esmCommonSize.shas, ...esmCoreSize.shas, ...shas
65 };
66
67 await buildSRIDigests(shas);
68
69 log("-----");
70 log("Embedded Lang :",
71 embedLanguages.map((el) => el.minified.length).reduce((acc, curr) => acc + curr, 0), "bytes");
72 log("All Lang :",
73 languages.map((el) => el.minified.length).reduce((acc, curr) => acc + curr, 0), "bytes");
74 log("highlight.js :",
75 size.fullSize, "bytes");
76
77 if (options.minify) {
78 log("highlight.min.js :", size.minified, "bytes");
79 log("highlight.min.js.gz :", zlib.gzipSync(size.minifiedSrc).length, "bytes");
80 } else {
81 log("highlight.js.gz :", zlib.gzipSync(size.fullSrc).length, "bytes");
82 }
83 if (options.esm) {
84 log("es/core.js :", esmCoreSize.fullSize, "bytes");
85 log("es/highlight.js :", esmCommonSize.fullSize, "bytes");
86 if (options.minify) {
87 log("es/core.min.js :", esmCoreSize.minified, "bytes");
88 log("es/core.min.js.gz :", zlib.gzipSync(esmCoreSize.minifiedSrc).length, "bytes");

Callers

nothing calls this directly

Calls 10

installFunction · 0.85
installPackageJSONFunction · 0.85
installStylesFunction · 0.85
getLanguagesFunction · 0.85
installLanguagesFunction · 0.85
filterFunction · 0.85
buildCoreFunction · 0.85
mkdirFunction · 0.85
buildSRIDigestsFunction · 0.85
logFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…