Skip to content

Commit

Permalink
feat(nuxt): export nuxt module
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdehaven committed Dec 11, 2024
1 parent cc5eaf6 commit a6039a4
Show file tree
Hide file tree
Showing 7 changed files with 821 additions and 93 deletions.
13 changes: 13 additions & 0 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,16 @@ You must import the CSS from the `@kong/kongponents` package along with Vue.
Kongponents for Vue</a> by Kong, Inc.
on <a href="https://codepen.io">CodePen</a>.
</iframe>

## Nuxt Module

You can also install Kongponents as a [Nuxt module](https://nuxt.com/docs/guide/directory-structure/modules).

1. Follow the [package install instructions](#install)
2. Add the Kongponents module to your `nuxt.config.ts`

```typescript
export default defineNuxtConfig({
modules: ['@kong/kongponents/nuxt'],
})
```
25 changes: 25 additions & 0 deletions module/kongponents.nuxt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { defineNuxtModule, createResolver, addComponentsDir } from '@nuxt/kit'

export interface ModuleOptions {
// Define module options here as needed
}

export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'kongponents',
configKey: 'kongponents',
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
setup(options, nuxt) {
const resolver = createResolver(import.meta.url)

addComponentsDir({
path: resolver.resolve('../src/components'),
pathPrefix: false,
prefix: '',
global: true,
})
},
})

// export * from './types'
20 changes: 20 additions & 0 deletions module/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": [
"vite/client",
"@nuxt/schema"
],
"outDir": "../dist/nuxt",
"declarationDir": "../dist/nuxt",
},
"include": [
"**/*.ts"
],
"exclude": [
"src/**",
"sandbox",
"node_modules",
"dist",
],
}
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
"require": "./dist/kongponents.umd.js",
"types": "./dist/types/index.d.ts"
},
"./nuxt": {
"import": "./dist/nuxt/kongponents-nuxt.es.js",
"require": "./dist/nuxt/kongponents-nuxt.cjs",
"types": "./dist/nuxt/kongponents.nuxt.d.ts"
},
"./package.json": "./package.json",
"./dist/*": "./dist/*"
},
"scripts": {
"build:cli": "rimraf ./bin && tsc --project ./cli/tsconfig.json && chmod u+x ./bin/index.js",
"build:docs": "vitepress build docs",
"build:kongponents": "pnpm typecheck && vite build && vue-tsc -p './tsconfig.build.json' --emitDeclarationOnly && tsc-alias -p './tsconfig.build.json'",
"build:kongponents": "pnpm typecheck && vite build && vue-tsc -p './tsconfig.build.json' --emitDeclarationOnly && tsc-alias -p './tsconfig.build.json' && pnpm build:nuxt:module",
"build:nuxt:module": "vue-tsc -p './module/tsconfig.json' --noEmit && vite build --config vite.config.nuxt.module.ts && vue-tsc -p './module/tsconfig.json' --emitDeclarationOnly",
"build:visualize": "cross-env-shell BUILD_VISUALIZER=true vite build -m production",
"build": "pnpm build:cli && pnpm stylelint && pnpm lint && pnpm build:kongponents && pnpm build:docs",
"build:ci": "pnpm build:kongponents && pnpm build:docs",
Expand Down Expand Up @@ -82,6 +88,8 @@
"@kong-ui-public/sandbox-layout": "^2.1.59",
"@kong/design-tokens": "^1.17.2",
"@kong/eslint-config-kong-ui": "^1.1.2",
"@nuxt/kit": "^3.14.1592",
"@nuxt/schema": "^3.14.1592",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@stylistic/stylelint-plugin": "^3.1.1",
Expand Down
Loading

0 comments on commit a6039a4

Please sign in to comment.