Skip to content

Commit

Permalink
fix(nuxt): use rc14+ compatible nuxt module
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Nov 16, 2022
1 parent a4dcf53 commit 98c4dc9
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 77 deletions.
36 changes: 13 additions & 23 deletions nuxt.mjs
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import { MagicRegExpTransformPlugin } from 'magic-regexp/transform'
import * as magicRegexp from 'magic-regexp'
import { defineNuxtModule, addImportsSources, addWebpackPlugin, addVitePlugin } from '@nuxt/kit'

export default function MagicRegExpNuxtModule() {
const nuxt = this.nuxt
nuxt.hook(
'autoImports:sources',
presets => {
presets.push({
from: 'magic-regexp',
imports: Object.keys(magicRegexp),
})
},
{ allowDeprecated: true }
)
export default defineNuxtModule({
setup(_options, nuxt) {
addImportsSources({
from: 'magic-regexp',
imports: Object.keys(magicRegexp),
})

// Disable RegExp code transformation in development mode
if (nuxt.options.dev) return
// Disable RegExp code transformation in development mode
if (nuxt.options.dev) return

nuxt.hook('webpack:config', config => {
config.plugins = config.plugins || []
config.plugins.push(MagicRegExpTransformPlugin.webpack())
})
nuxt.hook('vite:extendConfig', config => {
config.plugins = config.plugins || []
config.plugins.push(MagicRegExpTransformPlugin.vite())
})
}
addWebpackPlugin(MagicRegExpTransformPlugin.webpack())
addVitePlugin(MagicRegExpTransformPlugin.vite())
},
})
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"unplugin": "^0.10.2"
},
"devDependencies": {
"@nuxt/kit": "3.0.0",
"@nuxtjs/eslint-config-typescript": "latest",
"@release-it/conventional-changelog": "5.1.1",
"@types/estree": "1.0.0",
Expand All @@ -67,12 +68,13 @@
"pinst": "latest",
"prettier": "latest",
"release-it": "15.5.0",
"typescript": "4.9.3",
"typescript": "4.8.4",
"unbuild": "1.0.1",
"vite": "3.2.4",
"vitest": "0.25.2"
},
"resolutions": {
"typescript": "4.8.4",
"magic-regexp": "link:."
},
"packageManager": "[email protected]",
Expand Down
Loading

0 comments on commit 98c4dc9

Please sign in to comment.