fite/lib/thread.js

35 lines
842 B
JavaScript
Raw Permalink 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'
2023-06-16 14:19:32 +08:00
import { defaultCustomElement } 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
2023-06-16 14:19:32 +08:00
options.isCustomElement = options.isCustomElement
? Function('return ' + options.isCustomElement)()
: defaultCustomElement
2023-06-14 19:36:20 +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-16 14:19:32 +08:00
options.IS_MPA &&
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)