UNPKG

vite-plugin-react-server

Version:
41 lines (39 loc) 1.41 kB
/** * vite-plugin-react-server * Copyright (c) Nico Brinkkemper * MIT License */ import { join } from 'node:path'; import { pluginRoot } from '../../root.js'; import { messageHandler } from './messageHandler.js'; import { parentPort, MessageChannel } from 'node:worker_threads'; import { register } from 'node:module'; import { register as register$1 } from 'tsx/esm/api'; if (!parentPort) throw new Error("This module must be run as a worker"); const reactLoaderChannel = new MessageChannel(); const cssLoaderChannel = new MessageChannel(); reactLoaderChannel.port2.on("message", messageHandler); cssLoaderChannel.port2.on("message", messageHandler); const loaderPath = "file://" + join(pluginRoot, "loader/react-loader.js"); const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.js"); register(loaderPath, { parentURL: pluginRoot, data: { port: reactLoaderChannel.port1 }, transferList: [reactLoaderChannel.port1] }); register(cssLoaderPath, { parentURL: pluginRoot, data: { port: cssLoaderChannel.port1 }, transferList: [cssLoaderChannel.port1] }); register$1(); parentPort?.on("message", messageHandler); parentPort?.postMessage({ type: "READY", env: process.env["NODE_ENV"], pid: process.pid }); if (process.env["NODE_ENV"] !== "development") { throw new Error("This module must be run in development mode"); } //# sourceMappingURL=html-worker.development.js.map