一覧へ戻る
jafshare/rollup-plugin-worker-thread(新しいタブで開きます)
主要言語: TypeScript
提供rollup对nodejs的worker_threads的文件导入的支持
- star 数
- 2
- watcher 数
- 1
- fork 数
- 0
- issue 数
- 0
- 最終更新
- 2023/01/24
主要言語: TypeScript
提供rollup对nodejs的worker_threads的文件导入的支持
提供 rollup 对 nodejs 的 worker_threads 的支持,使用方法类似于 vite 的 ?worker 语法
npm i -D rollup-plugin-worker-thread
worker.ts
import { threadId } from "worker_threads"; async function task() { return new Promise((resolve) => { setTimeout(() => { console.log("(time)当前threadId:", threadId); resolve(void 0); }, 1500); }); } task();
main.ts
import { Worker } from "worker_threads"; import workPath from "./worker?worker"; // 使用?worker标识是一个worker文件 new Worker(workPath);
rollup.config.ts
import worker from "rollup-plugin-worker-thread"; export default defineConfig({ plugins: [worker()] });