Setup

Install magic-regexp from npm and (optionally) enable the build-time transform via a plugin.

First, install magic-regexp:

npm
pnpm
bun
yarn
npm i magic-regexp

Second, optionally, you can enable the included transform, which enables zero-runtime usage.

nuxt.config.ts
vite.config.ts
next.config.mjs
build.config.ts
// Nuxt 3
import { defineNuxtConfig } from 'nuxt'

export default defineNuxtConfig({
  // This will also enable auto-imports of magic-regexp helpers
  modules: ['magic-regexp/nuxt'],
})