Skip to content

Instantly share code, notes, and snippets.

@Yago
Last active May 5, 2022 08:12
Show Gist options
  • Save Yago/e30da10659faf233575bf8c8073c6f24 to your computer and use it in GitHub Desktop.
Save Yago/e30da10659faf233575bf8c8073c6f24 to your computer and use it in GitHub Desktop.

Spatie's Ray globally in a JS/TS project

Follow these steps to add Ray globally available in your JavaScript/TypeScript project:

  1. Create the required files
$ mkdir ./ray
$ touch ./ray/index.js
$ touch ./ray/ray.d.ts
  1. Import in your app's entry import 'path/to/ray';
  2. For TypeScript, be sure ray/ray.d.ts is somehow included in tsconfig.json
  3. Use it anywhere; f.ex ray('hello world);
/* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable global-require */
/* eslint-disable @typescript-eslint/no-var-requires */
const { Ray, ray } = require('node-ray/web');
Ray.useDefaultSettings({ intercept_console_log: true });
if (typeof window !== 'undefined') {
window.ray = ray;
} else {
global.ray = ray;
}
/* eslint-disable @typescript-eslint/no-explicit-any */
declare global {
const ray: any;
}
export {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment