├── docs
├── .vitepress
│ ├── .gitignore
│ └── config.ts
├── getting-started.md
├── package.json
└── index.md
├── playgrounds
├── .npmrc
├── app.vue
├── public
│ └── favicon.ico
├── tsconfig.json
├── .gitignore
├── nuxt.config.ts
├── README.md
└── package.json
├── packages
└── nuxt-module-template
│ ├── .gitignore
│ ├── src
│ ├── runtime
│ │ ├── client.ts
│ │ ├── server.ts
│ │ ├── composables
│ │ │ └── useSomething.ts
│ │ └── plugin.ts
│ ├── nuxt-types.d.ts
│ └── module.ts
│ ├── tsconfig.json
│ ├── test
│ └── module.test.ts
│ ├── build.config.ts
│ ├── scripts
│ └── readme.ts
│ └── package.json
├── .npmrc
├── CODEOWNERS
├── test
├── package.json
├── fixtures
│ └── basic
│ │ ├── app.vue
│ │ ├── nuxt.config.ts
│ │ ├── tsconfig.json
│ │ ├── package.json
│ │ └── server
│ │ └── api
│ │ └── todos.ts
└── basic.test.ts
├── renovate.json
├── .vscode
├── extensions.json
├── settings.json
└── repo.code-workspace
├── taze.config.ts
├── .gitignore
├── pnpm-workspace.yaml
├── .editorconfig
├── biome.json
├── dprint.json
├── .github
└── workflows
│ ├── ci.yaml
│ ├── release.yaml
│ └── actions
│ └── install
│ └── action.yaml
├── LICENSE
├── package.json
└── README.md
/docs/.vitepress/.gitignore:
--------------------------------------------------------------------------------
1 | cache
2 | dist
--------------------------------------------------------------------------------
/playgrounds/.npmrc:
--------------------------------------------------------------------------------
1 | shamefully-hoisted=true
--------------------------------------------------------------------------------
/packages/nuxt-module-template/.gitignore:
--------------------------------------------------------------------------------
1 | README.md
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | //registry.npmjs.org/:_authToken=${NPM_TOKEN}
2 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @hebilicious
--------------------------------------------------------------------------------
/playgrounds/app.vue:
--------------------------------------------------------------------------------
1 |
2 | Hello World !
3 |
4 |
--------------------------------------------------------------------------------
/test/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nuxt-module-template-test"
3 | }
4 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["github>Hebilicious/renovate-config"]
3 | }
4 |
--------------------------------------------------------------------------------
/docs/getting-started.md:
--------------------------------------------------------------------------------
1 | # Getting started
2 |
3 | ## 📦 Installation
4 |
5 | ...
6 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["dprint.dprint", "biomejs.biome"]
3 | }
4 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/src/runtime/client.ts:
--------------------------------------------------------------------------------
1 | export const hello = () => "hello client"
2 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/src/runtime/server.ts:
--------------------------------------------------------------------------------
1 | export const hello = () => "hello server"
2 |
--------------------------------------------------------------------------------
/taze.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "taze"
2 |
3 | export default defineConfig({})
4 |
--------------------------------------------------------------------------------
/test/fixtures/basic/app.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World !
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .nuxt
4 | .eslintcache
5 | .vitepress/cache
6 | .vitepress/dist
7 | .turbo
--------------------------------------------------------------------------------
/playgrounds/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hebilicious/nuxt-module-template/HEAD/playgrounds/public/favicon.ico
--------------------------------------------------------------------------------
/playgrounds/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | // https://nuxt.com/docs/guide/concepts/typescript
3 | "extends": "./.nuxt/tsconfig.json"
4 | }
5 |
--------------------------------------------------------------------------------
/test/fixtures/basic/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | export default defineNuxtConfig({
2 | modules: ["@hebilicious/nuxt-module-template"]
3 | })
4 |
--------------------------------------------------------------------------------
/playgrounds/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.log*
3 | .nuxt
4 | .nitro
5 | .cache
6 | .output
7 | .env
8 | dist
9 | .DS_Store
10 |
--------------------------------------------------------------------------------
/test/fixtures/basic/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | // https://nuxt.com/docs/guide/concepts/typescript
3 | "extends": "./.nuxt/tsconfig.json"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | // https://nuxt.com/docs/guide/concepts/typescript
3 | "extends": "./.nuxt/tsconfig.json"
4 | }
5 |
--------------------------------------------------------------------------------
/test/fixtures/basic/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "basic-fixture",
3 | "private": true,
4 | "dependencies": {
5 | "nuxt": "^3.14.1592"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/test/fixtures/basic/server/api/todos.ts:
--------------------------------------------------------------------------------
1 | export default defineEventHandler(() => {
2 | return [
3 | { id: 1, todo: "Hello" },
4 | { id: 2, todo: "World" }
5 | ]
6 | })
7 |
--------------------------------------------------------------------------------
/pnpm-workspace.yaml:
--------------------------------------------------------------------------------
1 | # We use pnpm to publish https://github.com/oven-sh/bun/issues/1976
2 | packages:
3 | - packages/**
4 | - playgrounds
5 | - test/fixtures/**
6 | - docs
7 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/test/module.test.ts:
--------------------------------------------------------------------------------
1 | import { describe, expect, it } from "vitest"
2 |
3 | describe("all", () => {
4 | it("tests", () => {
5 | expect(true).toBe(true)
6 | })
7 | })
8 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/src/runtime/composables/useSomething.ts:
--------------------------------------------------------------------------------
1 | import { useState } from "#imports"
2 |
3 | export function useSomething() {
4 | const something = useState("something", () => "something")
5 | return { something }
6 | }
7 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/build.config.ts:
--------------------------------------------------------------------------------
1 | import { defineBuildConfig } from "unbuild"
2 |
3 | export default defineBuildConfig({
4 | entries: ["src/module"],
5 | declaration: true,
6 | rollup: {
7 | emitCJS: true
8 | }
9 | })
10 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_size = 2
5 | indent_style = space
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.defaultFormatter": "dprint.dprint",
3 | "editor.formatOnSave": true,
4 | "editor.codeActionsOnSave": {
5 | "quickfix.biome": "explicit",
6 | "source.organizeImports.biome": "explicit"
7 | },
8 | "dprint.path": "./node_modules/.bin/dprint"
9 | }
10 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/src/nuxt-types.d.ts:
--------------------------------------------------------------------------------
1 | import type { ModuleOptions } from "./module"
2 |
3 | declare module "@nuxt/schema" {
4 | interface RuntimeConfig {
5 | "my-module": ModuleOptions
6 | }
7 | interface PublicRuntimeConfig {
8 | "my-module": ModuleOptions
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/scripts/readme.ts:
--------------------------------------------------------------------------------
1 | import { copyFileSync } from "node:fs"
2 | import { resolve } from "node:path"
3 | import { fileURLToPath } from "node:url"
4 |
5 | const dir = fileURLToPath(new URL("..", import.meta.url))
6 | copyFileSync(resolve(dir, "../../README.md"), resolve(dir, "./README.md"))
7 |
--------------------------------------------------------------------------------
/docs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@hebilicious/nuxt-module-template_docs",
3 | "private": true,
4 | "type": "module",
5 | "scripts": {
6 | "dev": "vitepress dev",
7 | "build": "vitepress build",
8 | "preview": "vitepress preview"
9 | },
10 | "devDependencies": {
11 | "vitepress": "^1.5.0"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/playgrounds/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | // https://nuxt.com/docs/api/configuration/nuxt-config
2 | export default defineNuxtConfig({
3 | modules: [
4 | "../packages/nuxt-module-template/src/module"
5 | // "@example/my-module"
6 | ],
7 | devtools: {
8 | enabled: true
9 | },
10 | compatibilityDate: "2024-11-22"
11 | })
12 |
--------------------------------------------------------------------------------
/biome.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3 | "linter": {
4 | "rules": {
5 | "correctness": {
6 | "noUnusedImports": { "level": "warn", "fix": "safe" }
7 | },
8 | "style": {
9 | "useConst": { "level": "warn", "fix": "safe" }
10 | }
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/playgrounds/README.md:
--------------------------------------------------------------------------------
1 | # AuthJS Nuxt
2 |
3 | This is a simple example to demonstrate how to use the module.
4 |
5 | ## Dependencies Caveats
6 |
7 | The dev dependencies are required for the build to work with pnpm.
8 | If you are using npm or `--shamefully-hoist=true`, you should be able to remove them from the `package.json` file.
9 |
--------------------------------------------------------------------------------
/.vscode/repo.code-workspace:
--------------------------------------------------------------------------------
1 | {
2 | "folders": [
3 | {
4 | "path": "../package/nuxt-module-template",
5 | },
6 | {
7 | "path": "..",
8 | },
9 | ],
10 | "settings": {
11 | "typescript.tsdk": "../node_modules/typescript/lib",
12 | "typescript.enablePromptUseWorkspaceTsdk": true
13 | },
14 | }
15 |
--------------------------------------------------------------------------------
/playgrounds/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@hebilicious/nuxt-module-template_playground",
3 | "private": true,
4 | "scripts": {
5 | "build": "NITRO_PRESET=cloudflare_pages nuxt build",
6 | "dev": "nuxt dev",
7 | "generate": "nuxt generate",
8 | "preview": "nuxt preview"
9 | },
10 | "devDependencies": {
11 | "@nuxt/devtools": "^3.0.0",
12 | "nuxt": "^4.1.2"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/src/runtime/plugin.ts:
--------------------------------------------------------------------------------
1 | import { useSomething } from "./composables/useSomething"
2 | import { defineNuxtPlugin, useRuntimeConfig } from "#imports"
3 |
4 | export default defineNuxtPlugin(async () => {
5 | const { something } = useSomething()
6 |
7 | const config = useRuntimeConfig()
8 |
9 | // eslint-disable-next-line no-console
10 | if (config) console.log(something)
11 | })
12 |
--------------------------------------------------------------------------------
/test/basic.test.ts:
--------------------------------------------------------------------------------
1 | import { fileURLToPath } from "node:url"
2 | import { describe, expect, it } from "vitest"
3 | import { $fetch, setup } from "@nuxt/test-utils"
4 |
5 | describe("basic test", async () => {
6 | await setup({
7 | rootDir: fileURLToPath(new URL("./fixtures/basic", import.meta.url))
8 | })
9 |
10 | it("displays data", async () => {
11 | // Get response to a server-rendered page with `$fetch`.
12 | const html = await $fetch("/")
13 | expect(html).toContain("Hello")
14 | expect(html).toContain("World")
15 | })
16 | })
17 |
--------------------------------------------------------------------------------
/docs/.vitepress/config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "vitepress"
2 |
3 | // https://vitepress.dev/reference/site-config
4 | export default defineConfig({
5 | title: "Nuxt Module Template",
6 | description: "A template for creating Nuxt modules",
7 | themeConfig: {
8 | // https://vitepress.dev/reference/default-theme-config
9 | nav: [
10 | { text: "Home", link: "/" },
11 | { text: "Get Started", link: "/getting-started" }
12 | ],
13 |
14 | sidebar: [
15 | {
16 | // text: 'AuthJS',
17 | items: [{ text: "Get Started", link: "/getting-started" }]
18 | }
19 | ],
20 |
21 | socialLinks: [{ icon: "github", link: "https://github.com/Hebilicious/nuxt-module-template" }]
22 | }
23 | })
24 |
--------------------------------------------------------------------------------
/dprint.json:
--------------------------------------------------------------------------------
1 | {
2 | "markdown": {},
3 | "biome": {
4 | "lineWidth": 100,
5 | "semicolons": "asNeeded",
6 | "trailingCommas": "none"
7 | },
8 | "malva": {},
9 | "markup": {
10 | "quotes": "double",
11 | "closingBracketSameLine": true,
12 | "vBindStyle": "short",
13 | "vOnStyle": "short",
14 | "vForDelimiterStyle": "of",
15 | "vSlotStyle": "short",
16 | "vBindSameNameShortHand": true
17 | },
18 | "excludes": ["**/node_modules", "**/.nuxt"],
19 | "plugins": [
20 | "https://plugins.dprint.dev/markdown-0.17.8.wasm",
21 | "https://plugins.dprint.dev/biome-0.6.0.wasm",
22 | "https://plugins.dprint.dev/g-plane/malva-v0.10.1.wasm",
23 | "https://plugins.dprint.dev/g-plane/markup_fmt-v0.13.1.wasm"
24 | ]
25 | }
26 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | # https://vitepress.dev/reference/default-theme-home-page
3 | layout: home
4 |
5 | hero:
6 | name: "Nuxt Module Template"
7 | text: "A template for your Nuxt modules"
8 | tagline: Use Nuxt module template to start your Nuxt projects.
9 | actions:
10 | - theme: brand
11 | text: Get Started
12 | link: /getting-started
13 |
14 | features:
15 | - title: Comprehensive Documentation 📚
16 | details: Access detailed documentation tailored to your needs, right when you need it.
17 | - title: Customizable 🔧
18 | details: Adapt Nuxt Module Template to fit your specific requirements with ease.
19 | - title: Extensible & Hackable 🔌
20 | details: Expand Nuxt Module Template's capabilities with custom integrations and modules.
21 | ---
22 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | pull_request:
9 | branches:
10 | - main
11 |
12 | jobs:
13 | lint:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
17 |
18 | - uses: ./.github/workflows/actions/install
19 | with:
20 | install: nuxt-module-template
21 |
22 | - name: Format
23 | run: bun run format
24 |
25 | test:
26 | runs-on: ubuntu-latest
27 |
28 | steps:
29 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
30 |
31 | - uses: ./.github/workflows/actions/install
32 |
33 | - name: Build
34 | run: bun run build
35 |
36 | - name: Test
37 | run: bun run test
38 |
39 | - name: Typecheck
40 | run: bun run typecheck
41 |
--------------------------------------------------------------------------------
/.github/workflows/release.yaml:
--------------------------------------------------------------------------------
1 | name: Release
2 |
3 | on:
4 | push:
5 | tags:
6 | - "v*"
7 |
8 | permissions:
9 | id-token: write
10 | contents: write
11 |
12 | jobs:
13 | release:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
17 | with:
18 | fetch-depth: 0
19 |
20 | - uses: ./.github/workflows/actions/install
21 | with:
22 | install: nuxt-module-template
23 |
24 | - run: bun x changelogithub
25 | continue-on-error: false
26 | env:
27 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
28 |
29 | - name: Build
30 | run: bun run build
31 |
32 | - name: Publish to NPM
33 | run: bun run publish:ci
34 | env:
35 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
36 | NPM_TOKEN: ${{secrets.NPM_TOKEN}}
37 | NPM_CONFIG_PROVENANCE: true
38 |
--------------------------------------------------------------------------------
/.github/workflows/actions/install/action.yaml:
--------------------------------------------------------------------------------
1 | name: Install Bun & PNPM
2 | inputs:
3 | install:
4 | description: Choose a specific package to install
5 | required: false
6 | node-version:
7 | required: false
8 | default: 22.9.0
9 | bun-version:
10 | required: false
11 | default: 1.1.34
12 | pnpm-version:
13 | required: false
14 | default: 9.14.2
15 |
16 | runs:
17 | using: composite
18 | steps:
19 | - name: Use Bun ${{ inputs.bun-version }}
20 | uses: oven-sh/setup-bun@v2
21 | with:
22 | bun-version: ${{ inputs.bun-version }}
23 |
24 | - name: Use Pnpm ${{ inputs.pnpm-version }}
25 | uses: pnpm/action-setup@v3
26 | with:
27 | version: ${{ inputs.pnpm-version }}
28 |
29 | - name: Use Node.js ${{ inputs.node-version }}
30 | uses: actions/setup-node@v6
31 | with:
32 | node-version: ${{ inputs.node-version }}
33 | cache: pnpm
34 |
35 | - name: Install dependencies
36 | run: pnpm install ${{ inputs.install && format('--filter {0}', inputs.install) || '' }}
37 | shell: bash
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023-PRESENT Hebilicious
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@hebilicious/nuxt-module-template",
3 | "type": "module",
4 | "version": "0.0.0",
5 | "author": {
6 | "name": "Hebilicious",
7 | "email": "xsh4k3@gmail.com",
8 | "url": "https://twitter.com/its_hebilicious"
9 | },
10 | "license": "MIT",
11 | "repository": "Hebilicious/nuxt-module-template",
12 | "exports": {
13 | ".": {
14 | "require": {
15 | "types": "./dist/module.d.cts",
16 | "default": "./dist/module.cjs"
17 | },
18 | "import": {
19 | "types": "./dist/module.d.mts",
20 | "default": "./dist/module.mjs"
21 | },
22 | "types": "./dist/module.d.ts",
23 | "default": "./dist/module.mjs"
24 | }
25 | },
26 | "main": "./dist/module.cjs",
27 | "module": "./dist/module.mjs",
28 | "types": "./dist/types.d.ts",
29 | "files": ["dist", "*.d.ts", "*.cjs", "*.mjs"],
30 | "scripts": {
31 | "readme": "bun scripts/readme.ts",
32 | "prebuild": "bun postinstall",
33 | "postinstall": "nuxi prepare",
34 | "postbuild": "bun readme",
35 | "build:stub": "nuxt-build-module --stub",
36 | "build:module": "nuxt-build-module",
37 | "build": "rimraf dist && bun build:module",
38 | "dev": "nuxi dev"
39 | },
40 | "peerDependencies": {
41 | "nuxt": "^4.1.2",
42 | "vite": "*"
43 | },
44 | "dependencies": {
45 | "@nuxt/kit": "^4.0.0",
46 | "defu": "^6.1.4"
47 | },
48 | "devDependencies": {
49 | "@nuxt/module-builder": "^0.8.4",
50 | "h3": "^1.13.0",
51 | "nuxt": "^4.1.2",
52 | "unbuild": "^3.5.0"
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nuxt-module-template",
3 | "type": "module",
4 | "version": "0.0.1",
5 | "private": true,
6 | "scripts": {
7 | "build": "rimraf packages/*/dist && cd packages/nuxt-module-template && bun run build",
8 | "format": "dprint check --verbose",
9 | "format:fix": "dprint fmt --verbose",
10 | "docs:dev": "cd docs && vitepress dev",
11 | "docs:build": "cd docs && vitepress build",
12 | "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
13 | "release": "bun format:fix && bumpp -r -x \"bun run changelog\" --all",
14 | "prepare:types": "cd packages/nuxt-module-template && nuxi prepare",
15 | "typecheck": "cd packages/nuxt-module-template && tsc --noEmit",
16 | "test": "vitest",
17 | "publish:ci": "pnpm -r publish --access public --no-git-checks",
18 | "test:all": "bun run lint && bun run typecheck && bun run vitest run"
19 | },
20 | "devDependencies": {
21 | "@biomejs/biome": "^2.0.4",
22 | "@nuxt/test-utils": "^3.14.4",
23 | "@types/node": "^24.9.2",
24 | "bumpp": "^10.0.3",
25 | "conventional-changelog-cli": "^5.0.0",
26 | "dprint": "^0.47.5",
27 | "lint-staged": "^16.0.0",
28 | "rimraf": "^6.0.1",
29 | "simple-git-hooks": "^2.11.1",
30 | "taze": "^19.0.0",
31 | "typescript": "^5.7.2",
32 | "vitest": "^4.0.1"
33 | },
34 | "engines": {
35 | "bun": "1.1.34",
36 | "node": "24.11.0",
37 | "pnpm": "9.14.2"
38 | },
39 | "packageManager": "pnpm@9.14.2",
40 | "simple-git-hooks": {
41 | "pre-commit": "pnpx lint-staged"
42 | },
43 | "lint-staged": {
44 | "*.{js,ts,tsx,vue,md}": ["dprint fmt --verbose"]
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ⚗️ Nuxt Module Template
2 |
3 | [](https://github.com/Hebilicious/nuxt-module-template/actions/workflows/ci.yaml)
4 | [](https://opensource.org/licenses/MIT)
5 |
6 | 🚀 Welcome to **Hebilicious Nuxt Module Starter Template**!
7 |
8 | This is a Pnpm and Bun powered Nuxt Module Repo Template Starter.
9 | It comes with a base module that you can use to start your own module.
10 |
11 | ## Batteries Included
12 |
13 | - 📦 pnpm monorepo
14 | - 📦 Bun script runner
15 | - 🏗️ Build Nuxt Module with `nuxt-build-module`
16 | - 🏗 ESM/CJS valid package, with MTS and CTS declaration files.
17 | - 📝 Docs with vitepress
18 | - ✅ Tests with vitest
19 | - 🔨 Publish with pnpm
20 | - 🔄 CI with Github Actions and bun
21 | - 🚀 Trigger NPM release + changelog from CLI
22 | - 📏 Conventional commits
23 | - 🔄 Renovate config
24 |
25 | ## 📦 Installation
26 |
27 | Use [pnpm](https://pnpm.io/installation#using-corepack) and [bun](https://bun.sh/docs/installation) for module development :
28 |
29 | ```bash
30 | pnpm i
31 | ```
32 |
33 | ## 🚀 Getting Started
34 |
35 | Do a search and replace for `@hebilicious/nuxt-module-template` and `nuxt-module-template` and replace with your scope and module name.
36 |
37 | ## 📦 Contributing
38 |
39 | Contributions, issues and feature requests are welcome!
40 |
41 | 1. Fork this repo
42 |
43 | 2. [Install `bun`.](https://bun.sh/docs/installation)
44 |
45 | 3. Intall pnpm `corepack enable && pnpm corepack use pnpm@latest`
46 |
47 | 4. Use `pnpm i` at the mono-repo root.
48 |
49 | 5. Make modifications and follow conventional commits.
50 |
51 | 6. Open a PR 🚀🚀🚀
52 |
--------------------------------------------------------------------------------
/packages/nuxt-module-template/src/module.ts:
--------------------------------------------------------------------------------
1 | import {
2 | addImports,
3 | addPlugin,
4 | addTemplate,
5 | createResolver,
6 | defineNuxtModule,
7 | useLogger
8 | } from "@nuxt/kit"
9 | import { defu } from "defu"
10 |
11 | const NAME = "my-module" as const
12 |
13 | export type ModuleOptions = Record
14 |
15 | export default defineNuxtModule({
16 | meta: {
17 | name: NAME,
18 | configKey: NAME
19 | },
20 | setup(userOptions, nuxt) {
21 | const logger = useLogger(NAME)
22 | const { resolve } = createResolver(import.meta.url)
23 |
24 | logger.info(`Adding ${NAME} module...`, userOptions)
25 | // 1. Set up runtime configuration
26 | const options = defu(nuxt.options.runtimeConfig.public[NAME], userOptions, {})
27 | nuxt.options.runtimeConfig.public[NAME] = options
28 |
29 | // 3. Add composables
30 | addImports([{ name: "useSomething", from: resolve("./runtime/composables/useSomething") }])
31 |
32 | // 4. Create virtual imports for server-side
33 | // @todo Contribute an helper to nuxt/kit to handle this scenario like this
34 | // addLibrary({name: "#auth", entry: "./runtime/lib", clientEntry: "./runtime/lib/client", serverEntry: "./runtime/lib/server"})
35 |
36 | // These will be available only in the /server directory
37 | nuxt.hook("nitro:config", (nitroConfig) => {
38 | nitroConfig.alias = nitroConfig.alias || {}
39 | nitroConfig.alias[`#${NAME}`] = resolve("./runtime/server")
40 | })
41 |
42 | // These will be available outside of the /server directory
43 | nuxt.options.alias[`#${NAME}`] = resolve("./runtime/client")
44 |
45 | // 4. Add types
46 | const filename = `types/${NAME}.d.ts`
47 | addTemplate({
48 | filename,
49 | getContents: () =>
50 | [
51 | `declare module '#${NAME}' {`,
52 | ` const hello: typeof import('${resolve("./runtime/server")}').hello`,
53 | "}"
54 | ].join("\n")
55 | })
56 |
57 | nuxt.hook("prepare:types", (options) => {
58 | options.references.push({ path: resolve(nuxt.options.buildDir, filename) })
59 | })
60 |
61 | // 5. Add plugin & middleware
62 | addPlugin(resolve("./runtime/plugin"))
63 |
64 | logger.success(`Added ${NAME} module successfully.`)
65 | }
66 | })
67 |
--------------------------------------------------------------------------------