rollup-plugin-worker-thread
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

rollup-plugin-worker-thread

提供 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()]
});

Package Sidebar

Install

npm i rollup-plugin-worker-thread

Weekly Downloads

2

Version

1.0.3

License

none

Unpacked Size

5.09 kB

Total Files

6

Last publish

Collaborators

  • jianganfu