Skip to content

Commit 98c4dc9

Browse files
committed
fix(nuxt): use rc14+ compatible nuxt module
1 parent a4dcf53 commit 98c4dc9

File tree

3 files changed

+331
-77
lines changed

3 files changed

+331
-77
lines changed

nuxt.mjs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
import { MagicRegExpTransformPlugin } from 'magic-regexp/transform'
22
import * as magicRegexp from 'magic-regexp'
3+
import { defineNuxtModule, addImportsSources, addWebpackPlugin, addVitePlugin } from '@nuxt/kit'
34

4-
export default function MagicRegExpNuxtModule() {
5-
const nuxt = this.nuxt
6-
nuxt.hook(
7-
'autoImports:sources',
8-
presets => {
9-
presets.push({
10-
from: 'magic-regexp',
11-
imports: Object.keys(magicRegexp),
12-
})
13-
},
14-
{ allowDeprecated: true }
15-
)
5+
export default defineNuxtModule({
6+
setup(_options, nuxt) {
7+
addImportsSources({
8+
from: 'magic-regexp',
9+
imports: Object.keys(magicRegexp),
10+
})
1611

17-
// Disable RegExp code transformation in development mode
18-
if (nuxt.options.dev) return
12+
// Disable RegExp code transformation in development mode
13+
if (nuxt.options.dev) return
1914

20-
nuxt.hook('webpack:config', config => {
21-
config.plugins = config.plugins || []
22-
config.plugins.push(MagicRegExpTransformPlugin.webpack())
23-
})
24-
nuxt.hook('vite:extendConfig', config => {
25-
config.plugins = config.plugins || []
26-
config.plugins.push(MagicRegExpTransformPlugin.vite())
27-
})
28-
}
15+
addWebpackPlugin(MagicRegExpTransformPlugin.webpack())
16+
addVitePlugin(MagicRegExpTransformPlugin.vite())
17+
},
18+
})

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"unplugin": "^0.10.2"
5151
},
5252
"devDependencies": {
53+
"@nuxt/kit": "3.0.0",
5354
"@nuxtjs/eslint-config-typescript": "latest",
5455
"@release-it/conventional-changelog": "5.1.1",
5556
"@types/estree": "1.0.0",
@@ -67,12 +68,13 @@
6768
"pinst": "latest",
6869
"prettier": "latest",
6970
"release-it": "15.5.0",
70-
"typescript": "4.9.3",
71+
"typescript": "4.8.4",
7172
"unbuild": "1.0.1",
7273
"vite": "3.2.4",
7374
"vitest": "0.25.2"
7475
},
7576
"resolutions": {
77+
"typescript": "4.8.4",
7678
"magic-regexp": "link:."
7779
},
7880
"packageManager": "[email protected]",

0 commit comments

Comments
 (0)