
Product
Introducing Supply Chain Attack Campaigns Tracking in the Socket Dashboard
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.
$ npm install --save offroad
Add some "paths" entries to your tsconfig.json file:
// tsconfig.json
{
"compilerOptions": {
// ...
"paths": {
"worker:*.ts": ["./src/*.d.ts"],
"worker:*": ["./src/*.d", "./src/*.d.ts"]
}
}
}
Attach the Vite plugin:
// vite.config.ts
import { defineConfig } from "vite";
import { offroad } from "offroad/vite";
export default defineConfig({
plugins: [
offroad(),
],
});
Use define to define a potential bridge:
// example.ts
import { define } from "offroad";
// IMPORTANT: Must be `default` export!
export default define({
add(a: number, b: number): number {
return a + b;
},
});
Now, anywhere in your Vite application, you may use the example.ts file as per normal:
import example from "./example.ts";
let value = example.add(1, 2); //-> 3
However, you may also import the example.ts as a bridge to a Worker. This is done by adding the worker: prefix to your import statement.
Doing so allows you to interface with the file exactly the same, except now all methods are Promises!
import example from "worker:./example.ts";
let value = await example.add(1, 2); //-> 3
If are unsure if you want a Worker or not, or if you have dynamic/runtime conditions that determine your ability to use a Worker, you may use the offroad helper to conditionally load a module as a Bridge to a Worker or load the module directly:
import { offroad } from "offroad";
// Your custom logic
declare const useWorker: () => boolean;
const example = await offroad(useWorker, {
worker: () => import("worker:./example"),
fallback: () => import("./example"),
});
// Option 1:
// Always `await`
let foo = await example.add(2, 3); //-> 5
// Option 2:
// Use `isBridge` to determine if is Bridge (async) or not
import { isBridge } from "offroad";
if (isBridge(example)) {
// Bridge <-> Worker
await example.add(2, 3); //-> 5
} else {
// Direct / Main thread
example.add(2, 3); //-> 5
}
MIT © Luke Edwards
FAQs
todo
The npm package offroad receives a total of 0 weekly downloads. As such, offroad popularity was classified as not popular.
We found that offroad demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.

Security News
Node.js 25.4.0 makes require(esm) stable, formalizing CommonJS and ESM compatibility across supported Node versions.