35 lines
842 B
JavaScript
35 lines
842 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 { defaultCustomElement } from './utils.js'
|
|
|
|
const { options, verbose, dist, imports } = workerData
|
|
|
|
options.isCustomElement = options.isCustomElement
|
|
? Function('return ' + options.isCustomElement)()
|
|
: defaultCustomElement
|
|
|
|
async function doJob(job) {
|
|
let [currentPage, { page, files }] = job.entries().next().value
|
|
|
|
options.IS_MPA &&
|
|
console.log(
|
|
currentPage
|
|
? `正在生成 ${currentPage}.html ...`
|
|
: '\n正在解析公共依赖 ...'
|
|
)
|
|
|
|
await compileFiles(currentPage, page, files, options, {
|
|
verbose,
|
|
dist,
|
|
imports
|
|
})
|
|
parentPort.postMessage('ok')
|
|
}
|
|
|
|
parentPort.on('message', doJob)
|