Skip to content

Commit a641341

Browse files
committed
refactor: improve nuxt module
1 parent c68af44 commit a641341

File tree

5 files changed

+116
-18
lines changed

5 files changed

+116
-18
lines changed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sxzz } from '@sxzz/eslint-config'
22

3-
export default sxzz({
3+
export default sxzz().append({
44
ignores: ['README*.md/*.js'],
55
})

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@
6262
"test": "vitest"
6363
},
6464
"dependencies": {
65+
"@nuxt/kit": "^4.2.0",
6566
"es-module-lexer": "^1.7.0",
6667
"magic-string": "^0.30.21",
6768
"unplugin": "^2.3.10"
6869
},
6970
"devDependencies": {
71+
"@nuxt/schema": "^4.2.0",
7072
"@sxzz/eslint-config": "^7.2.8",
7173
"@sxzz/prettier-config": "^2.2.4",
7274
"@types/node": "^24.10.0",

pnpm-lock.yaml

Lines changed: 94 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/style.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function transformStyle(
9898
})
9999
return ret
100100
})
101-
.filter((s) => s)
101+
.filter(Boolean)
102102
.join('\n')
103103

104104
const lastSpecifier = specifiers.at(-1)!

src/nuxt.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
import { addBuildPlugin, defineNuxtModule } from '@nuxt/kit'
12
import type { Options } from './core/types'
2-
import unplugin from '.'
3+
import unplugin from './index'
4+
import type { NuxtModule } from '@nuxt/schema'
35

4-
// eslint-disable-next-line import/no-default-export
5-
export default function (this: any, options: Options): void {
6-
// install webpack plugin
7-
this.extendBuild((config: any) => {
8-
config.plugins = config.plugins || []
9-
config.plugins.unshift(unplugin.webpack(options))
10-
})
6+
const module: NuxtModule<Options, Options, false> = defineNuxtModule({
7+
meta: {
8+
name: 'unplugin-element-plus',
9+
configKey: 'elementPlus',
10+
},
11+
setup(options: Options) {
12+
addBuildPlugin({
13+
vite: () => unplugin.vite(options),
14+
webpack: () => unplugin.webpack(options),
15+
rspack: () => unplugin.rspack(options),
16+
})
17+
},
18+
})
1119

12-
// install vite plugin
13-
this.nuxt.hook('vite:extend', (vite: any) => {
14-
vite.config.plugins = vite.config.plugins || []
15-
vite.config.plugins.push(unplugin.vite(options))
16-
})
17-
}
20+
// eslint-disable-next-line import/no-default-export
21+
export default module

0 commit comments

Comments
 (0)