Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nuxt, vite components auto-import #70

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint:fix": "eslint . --fix",
"test": "pnpm -r test",
"release": "pnpm -r release && changeset publish",
"build:package": "pnpm --filter vaul-vue build-only",
"build:package": "pnpm --filter vaul-vue build-only && pnpm run --filter plugins build",
"build:playground": "pnpm build:package && pnpm --filter playground build"
},
"devDependencies": {
Expand Down
43 changes: 43 additions & 0 deletions packages/plugins/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig([
{
name: 'Nuxt module',
entries: ['./src/nuxt/index'],
outDir: '../vaul-vue/dist',
clean: false,
declaration: true,
externals: [
'@nuxt/schema',
],
rollup: {
emitCJS: true,
},
},
{
name: 'Unplugin-vue-component Resolver',
entries: ['./src/resolver/index'],
outDir: '../vaul-vue/dist',
clean: false,
declaration: true,
externals: [
'unplugin-vue-components',
],
rollup: {
emitCJS: true,
},
},
{
name: 'Namespaced',
entries: ['./src/namespaced/index'],
outDir: '../vaul-vue/dist',
clean: false,
declaration: true,
externals: [
'radix-vue',
],
rollup: {
emitCJS: true,
},
},
])
26 changes: 26 additions & 0 deletions packages/plugins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "plugins",
"type": "module",
"version": "1.9.9",
"description": "Nuxt module for Vaul Vue",
"license": "MIT",
"keywords": [
"vaul",
"vaul-vue",
"nuxt-module",
"nuxt",
"nuxt3"
],
"sideEffects": false,
"scripts": {
"build": "unbuild",
"stub": "unbuild --stub"
},
"dependencies": {
"@nuxt/kit": "^3.12.2",
"@nuxt/schema": "^3.12.2",
"unbuild": "^2.0.0",
"unplugin-vue-components": "^0.27.2",
"vaul-vue": "link:../vaul-vue"
}
}
23 changes: 23 additions & 0 deletions packages/plugins/src/namespaced/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { DrawerRoot, DrawerClose, DrawerContent, DrawerDescription, DrawerPortal, DrawerTitle, DrawerTrigger, DrawerOverlay, DrawerRootNested } from 'vaul-vue'

export const Drawer = {
Root: DrawerRoot,
Content: DrawerContent,
Overlay: DrawerOverlay,
RootNested: DrawerRootNested,
Close: DrawerClose,
Portal: DrawerPortal,
Trigger: DrawerTrigger,
Title: DrawerTitle,
Description: DrawerDescription,
} as {
Root: typeof DrawerRoot
Content: typeof DrawerContent
Overlay: typeof DrawerOverlay
RootNested: typeof DrawerRootNested
Close: typeof DrawerClose
Portal: typeof DrawerPortal
Trigger: typeof DrawerTrigger
Title: typeof DrawerTitle
Description: typeof DrawerDescription
}
30 changes: 30 additions & 0 deletions packages/plugins/src/nuxt/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { addComponent, defineNuxtModule } from '@nuxt/kit'
import { components } from '../../../vaul-vue/constant'

import type { } from '@nuxt/schema' // workaround for TS bug with "phantom" deps

export interface ModuleOptions {
prefix: string
}

export default defineNuxtModule<ModuleOptions>({
meta: {
name: '@vaul-vue/nuxt',
configKey: 'vaul',
compatibility: {
nuxt: '>=3.0.0',
},
},
defaults: {
prefix: ''
},
setup(options) {
for (const component of components) {
addComponent({
name: `${options.prefix}${component}`,
export: component,
filePath: 'vaul-vue',
})
}
},
})
30 changes: 30 additions & 0 deletions packages/plugins/src/resolver/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { ComponentResolver } from 'unplugin-vue-components'
import { components } from '../../../vaul-vue/constant'

export interface ResolverOptions {
/**
* prefix for components used in templates
*
* @defaultValue ""
*/
prefix?: string
}

export default function (options: ResolverOptions = {}): ComponentResolver {
const { prefix = '' } = options

return {
type: 'component',
resolve: (name: string) => {
if (name.toLowerCase().startsWith(prefix.toLowerCase())) {
const componentName = name.substring(prefix.length)
if (components.includes(componentName)) {
return {
name: componentName,
from: 'vaul-vue',
}
}
}
},
}
}
10 changes: 10 additions & 0 deletions packages/plugins/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "es2020",
"moduleResolution": "node"
},
"exclude": [
"node_modules",
"dist"
]
}
11 changes: 11 additions & 0 deletions packages/vaul-vue/constant/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const components = [
'DrawerRoot',
'DrawerContent',
'DrawerOverlay',
'DrawerRootNested',
'DrawerClose',
'DrawerPortal',
'DrawerTrigger',
'DrawerTitle',
'DrawerDescription',
]
30 changes: 30 additions & 0 deletions packages/vaul-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs"
},
"./namespaced": {
"import": {
"types": "./dist/namespaced/index.d.mts",
"default": "./dist/namespaced/index.mjs"
},
"require": {
"types": "./dist/namespaced/index.d.cts",
"default": "./dist/namespaced/index.cjs"
}
},
"./nuxt": {
"import": {
"types": "./dist/nuxt/index.d.mts",
"default": "./dist/nuxt/index.mjs"
},
"require": {
"types": "./dist/nuxt/index.d.cts",
"default": "./dist/nuxt/index.cjs"
}
},
"./resolver": {
"import": {
"types": "./dist/resolver/index.d.mts",
"default": "./dist/resolver/index.mjs"
},
"require": {
"types": "./dist/resolver/index.d.cts",
"default": "./dist/resolver/index.cjs"
}
}
},
"main": "./dist/index.umd.cjs",
Expand Down
Loading