🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More
Socket
Book a DemoSign in
Socket

rollup-plugin-worker-thread

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-worker-thread

提供 rollup 对 nodejs 的 worker_threads 的支持,使用方法类似于 vite 的 ?worker 语法

latest
npmnpm
Version
1.0.3
Version published
Weekly downloads
13
44.44%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

rollup

FAQs

Package last updated on 24 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts