
Product
Introducing Custom Tabs for Org Alerts
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.
$ 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 2 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
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.