Skip to content

Commit 96cbe8a

Browse files
committedOct 29, 2024·
feat: add vue-sonner for nuxt module
1 parent deaf385 commit 96cbe8a

File tree

7 files changed

+101
-129
lines changed

7 files changed

+101
-129
lines changed
 

‎.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ temp
2525
*.sln
2626
*.sw?
2727

28-
components.d.ts
28+
components.d.ts
29+
30+
.nuxt
31+
playground/.nuxt

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dev": "vite",
88
"dev:playground": "nuxi dev playground",
99
"dev:build": "nuxi build playground",
10-
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
10+
"dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
1111
"build:dev": "vite build --mode lib --watch",
1212
"build:docs": "vite build --mode docs",
1313
"build:lib": "vite build --mode lib && pnpm run build:types",
@@ -73,6 +73,7 @@
7373
"unplugin-vue-components": "^0.27.4",
7474
"vite": "^5.4.9",
7575
"vue": "^3.5.12",
76+
"vue-sonner": "^1.2.3",
7677
"vue-tsc": "^2.1.6"
7778
},
7879
"dependencies": {

‎playground/nuxt.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default defineNuxtConfig({
2-
modules: ['../src/module'],
2+
modules: ['../lib/nuxt'],
33
devtools: { enabled: true },
44
compatibilityDate: '2024-04-03'
55
})

‎pnpm-lock.yaml

+75-95
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/module/index.ts ‎src/module.ts

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import {
2-
defineNuxtModule,
3-
addPlugin,
4-
addComponent,
5-
createResolver
6-
} from '@nuxt/kit'
1+
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
72

83
import type { NuxtModule } from '@nuxt/schema'
94

10-
// Define module options interface
11-
interface ModuleOptions {
12-
// Add your module options here if needed
13-
}
5+
interface ModuleOptions {}
146

157
const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
168
meta: {
@@ -20,21 +12,15 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
2012
nuxt: '^3.0.0'
2113
}
2214
},
23-
// Explicitly type the setup function
15+
defaults: {},
2416
setup(options: ModuleOptions, nuxt) {
25-
const resolver = createResolver(import.meta.url)
17+
const { resolve } = createResolver(import.meta.url)
2618

27-
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
2819
addPlugin({
29-
src: resolver.resolve('./runtime/plugin'),
20+
src: resolve('./runtime/plugin'),
3021
mode: 'client'
3122
})
3223

33-
addComponent({
34-
name: 'Toaster',
35-
filePath: resolver.resolve('../packages/Toaster.vue')
36-
})
37-
3824
if (!nuxt.options.build.transpile) nuxt.options.build.transpile = []
3925
const transpileList = ['vue-sonner']
4026
transpileList.forEach((pkgName) => {

‎src/module/runtime/plugin.ts

-12
This file was deleted.

‎src/runtime/plugin.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Toaster, toast } from 'vue-sonner'
2+
import { defineNuxtPlugin } from 'nuxt/app'
3+
4+
import type { NuxtApp } from 'nuxt/app'
5+
6+
export default defineNuxtPlugin((nuxtApp: NuxtApp) => {
7+
nuxtApp.vueApp.component('Toaster', Toaster)
8+
9+
return {
10+
provide: {
11+
toast
12+
}
13+
}
14+
})

0 commit comments

Comments
 (0)
Please sign in to comment.