(name, languages, options)
| 200 | }); |
| 201 | |
| 202 | async 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 |
| 254 | module.exports.buildCore = buildCore; |
no test coverage detected
searching dependent graphs…