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