29 lines
741 B
JavaScript
29 lines
741 B
JavaScript
/**
|
|
* 子线程
|
|
* @author yutent<yutent.io@gmail.com>
|
|
* @date 2023/06/14 16:15:39
|
|
*/
|
|
import { parentPort, workerData } from 'node:worker_threads'
|
|
import { compileFiles } from './compile.js'
|
|
import { isCustomElement } from './utils.js'
|
|
|
|
const { options, verbose, dist, imports } = workerData
|
|
|
|
options.isCustomElement = Function('return ' + options.isCustomElement)()
|
|
|
|
async function doJob(job) {
|
|
let [currentPage, { page, files }] = job.entries().next().value
|
|
|
|
console.log(
|
|
currentPage ? `正在生成 ${currentPage}.html ...` : '\n正在解析公共依赖 ...'
|
|
)
|
|
await compileFiles(currentPage, page, files, options, {
|
|
verbose,
|
|
dist,
|
|
imports
|
|
})
|
|
parentPort.postMessage('ok')
|
|
}
|
|
|
|
parentPort.on('message', doJob)
|