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
|
2024-07-25 15:24:06 +08:00
|
|
|
const { ABS_CONFIG_FILEPATH } = options
|
2023-06-14 19:36:20 +08:00
|
|
|
|
2024-07-25 15:24:06 +08:00
|
|
|
const { compileOptions = {}, plugin = [] } = await import(
|
|
|
|
ABS_CONFIG_FILEPATH
|
|
|
|
).then(r => r.default)
|
2023-06-14 19:36:20 +08:00
|
|
|
|
2024-07-25 15:24:06 +08:00
|
|
|
const { isCustomElement = defaultCustomElement } = compileOptions
|
|
|
|
options.isCustomElement = isCustomElement
|
|
|
|
options.plugin = plugin
|
|
|
|
|
|
|
|
//
|
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-16 14:19:32 +08:00
|
|
|
options.IS_MPA &&
|
|
|
|
console.log(
|
|
|
|
currentPage
|
|
|
|
? `正在生成 ${currentPage}.html ...`
|
|
|
|
: '\n正在解析公共依赖 ...'
|
|
|
|
)
|
|
|
|
|
2023-06-16 12:11:43 +08:00
|
|
|
await compileFiles(currentPage, page, files, options, {
|
|
|
|
verbose,
|
|
|
|
dist,
|
|
|
|
imports
|
|
|
|
})
|
2024-07-25 15:24:06 +08:00
|
|
|
parentPort.postMessage(true)
|
2023-06-16 12:11:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
parentPort.on('message', doJob)
|