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

Function buildCore

tools/build_browser.js:202–251  ·  view source on GitHub ↗
(name, languages, options)

Source from the content-addressed store, hash-verified

200});
201
202async function buildCore(name, languages, options) {
203 const header = buildHeader();
204 let relativePath = "";
205 const input = {
206 ...config.rollup.core.input,
207 input: `src/stub.js`
208 };
209 input.plugins = [
210 ...input.plugins,
211 builtInLanguagesPlugin(languages)
212 ];
213 const output = {
214 ...(options.format === "es" ? config.rollup.node.output : config.rollup.browser_iife.output),
215 file: `${process.env.BUILD_DIR}/${name}.js`
216 };
217
218 // optimize for no languages by not including the language loading stub
219 if (languages.length === 0) {
220 input.input = "src/highlight.js";
221 }
222
223 if (options.format === "es") {
224 output.format = "es";
225 output.file = `${process.env.BUILD_DIR}/es/${name}.js`;
226 relativePath = "es/";
227 }
228
229 log(`Building ${relativePath}${name}.js.`);
230
231 const index = await rollupCode(input, output);
232 const sizeInfo = { shas: [] };
233 const writePromises = [];
234 if (options.minify) {
235 const { code } = await Terser.minify(index, { ...config.terser, module: (options.format === "es") });
236 const src = `${header}\n${code}`;
237 writePromises.push(fs.writeFile(output.file.replace(/js$/, "min.js"), src));
238 sizeInfo.minified = src.length;
239 sizeInfo.minifiedSrc = src;
240 sizeInfo.shas[`${relativePath}${name}.min.js`] = bundling.sha384(src);
241 }
242 {
243 const src = `${header}\n${index}`;
244 writePromises.push(fs.writeFile(output.file, src));
245 sizeInfo.fullSize = src.length;
246 sizeInfo.fullSrc = src;
247 sizeInfo.shas[`${relativePath}${name}.js`] = bundling.sha384(src);
248 }
249 await Promise.all(writePromises);
250 return sizeInfo;
251}
252
253// CDN build uses the exact same highlight.js distributable
254module.exports.buildCore = buildCore;

Callers 2

buildCDNFunction · 0.85
buildBrowserFunction · 0.85

Calls 4

buildHeaderFunction · 0.85
builtInLanguagesPluginFunction · 0.85
rollupCodeFunction · 0.85
logFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…