First, install magic-regexp
:
npm npm install magic-regexp
Copy to clipboard yarn yarn add magic-regexp
Copy to clipboard pnpm pnpm install magic-regexp
Copy to clipboard Second, optionally, you can enable the included transform, which enables zero-runtime usage .
nuxt.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 ' ] , } )
Copy to clipboard vite.config.ts import { defineConfig } from ' vite ' import { MagicRegExpTransformPlugin } from ' magic-regexp/transform ' export default defineConfig ( { plugins : [MagicRegExpTransformPlugin . vite ()] , } )
Copy to clipboard next.config.mjs // or, if using next.config.js // const { MagicRegExpTransformPlugin } = require('magic-regexp/transform') import { MagicRegExpTransformPlugin } from ' magic-regexp/transform ' export default { webpack ( config ) { config . plugins = config . plugins || [] config . plugins . push ( MagicRegExpTransformPlugin . webpack ()) return config } , }
Copy to clipboard build.config.ts // unbuild import { defineBuildConfig } from ' unbuild ' import { MagicRegExpTransformPlugin } from ' magic-regexp/transform ' export default defineBuildConfig ( { hooks : { ' rollup:options ' : ( options , config ) => { config . plugins . push ( MagicRegExpTransformPlugin . rollup ()) }, } , } )
Copy to clipboard