fite/lib/thread.js

29 lines
741 B
JavaScript
Raw Normal View History

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'
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)()
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正在解析公共依赖 ...'
)
await compileFiles(currentPage, page, files, options, {
verbose,
dist,
imports
})
2023-06-15 19:43:21 +08:00
parentPort.postMessage('ok')
}
parentPort.on('message', doJob)