• Stars
    star
    202
  • Rank 187,362 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated 15 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Complete solution to build Nuxt Modules.

๐Ÿ“ฆ Nuxt Module Builder

npm version License npm downloads Volta board

The complete solution to build and ship Nuxt modules.

Features

  • Compatible with Nuxt 3 and Nuxt Kit
  • Unified build with unjs/unbuild
  • Automated build config using last module spec
  • Typescript and ESM support
  • Auto generated CommonJS stubs
  • Auto generated types and shims for @nuxt/schema

We recommend to checkout the Nuxt modules author guide before starting with the module-builder.

Requirements

For a user to use a module generated from module-builder, it's recommended they have:

  • Node.js >= 16.x. Latest Node LTS preferred
  • Nuxt 3 or Nuxt Bridge. Nuxt 2 is functional but not advised

Quick start

Get started with our module starter:

npx nuxi init -t module my-module

Project structure

The module builder requires a special project structur. You can checkout the module template.

src/module.ts

The entrypoint for module definition.

A default export using defineNuxtModule and ModuleOptions type export is expected.

You could also optionally export ModuleHooks to annotate any custom hooks the module uses.

import { defineNuxtModule } from '@nuxt/kit'

export interface ModuleOptions {
  apiKey: string
}

export interface ModuleHooks {
  'my-module:init': any
}

export interface ModulePublicRuntimeConfig {
  NAME: string
}

export interface ModulePrivateRuntimeConfig {
  PRIVATE_NAME: string
}

export default defineNuxtModule<ModuleOptions>({
  meta: {
    name: 'my-module',
    configKey: 'myModule'
  },
  defaults: {
    apiKey: 'test'
  },
  async setup (moduleOptions, nuxt) {
    // Write module logic in setup function
  }
})

src/runtime/

Any runtime file and code that we need to provide by module including plugins, composables and server api, should be in this directory.

Each file will be transformed individually using unjs/mkdist to dist/runtime/.

package.json:

A minimum package.json should look like this:

{
  "name": "my-module",
  "license": "MIT",
  "version": "1.0.0",
  "exports": {
    ".": {
      "import": "./dist/module.mjs",
      "require": "./dist/module.cjs"
    }
  },
  "main": "./dist/module.cjs",
  "types": "./dist/types.d.ts",
  "files": [
    "dist"
  ],
  "scripts": {
    "prepack": "nuxt-module-build"
  },
  "dependencies": {
    "@nuxt/kit": "npm:@nuxt/kit-edge@latest"
  },
  "devDependencies": {
    "@nuxt/module-builder": "latest"
  }
}

Dist files

Module builder generates dist files in dist/ directory:

  • module.mjs: Module entrypoint build from src/module
  • module.json: Module meta extracted from module.mjs + package.json
  • module.cjs: ESM proxy to allow require module in CommonJS context
  • types.d.ts: Exported types in addition to shims for nuxt.config auto completion.
  • runtime/*: Individually transformed files using unjs/mkdist
    • Javascript and .ts files will be transformed to .mjs with extracted types on .d.ts file with same name
    • .vue files will be transformed with extracted .d.ts file
    • Other files will be copied as is

๐Ÿ’ป Development

  • Clone repository
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Try building example module using pnpm example:build

License

MIT - Made with ๐Ÿ’š

More Repositories

1

nuxt

The Intuitive Vue Framework.
TypeScript
51,559
star
2

framework

Old repo of Nuxt 3 framework, now on nuxt/nuxt
10,721
star
3

awesome

A curated list of awesome things related to Nuxt.js
5,014
star
4

vue-meta

Manage HTML metadata in Vue.js components with SSR support
JavaScript
4,064
star
5

create-nuxt-app

Create Nuxt.js App in seconds.
JavaScript
3,451
star
6

ui

A UI Library for Modern Web Apps, powered by Vue & Tailwind CSS.
Vue
3,316
star
7

content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
TypeScript
2,976
star
8

devtools

Unleash Nuxt Developer Experience
Vue
2,681
star
9

website-v2

Nuxt 2 Documentation Website
Vue
2,241
star
10

movies

๐Ÿฟ A TMDB client built with Nuxt 3
Vue
1,818
star
11

vite

โšก Vite Experience with Nuxt 2
TypeScript
1,385
star
12

image

Plug-and-play image optimization for Nuxt applications.
TypeScript
1,247
star
13

hackernews

HackerNews clone built with Nuxt.
Vue
1,197
star
14

components

Scan and auto import components for Nuxt.js 2.13+
TypeScript
879
star
15

modules

Discover the Nuxt modules to add any CMS, Database, UI, Auth and integrations into your Vue application.
TypeScript
871
star
16

example-auth0

A simple example that shows how to use Nuxt.js with Auth0.
Vue
713
star
17

vercel-builder

Vercel Builder for Nuxt
TypeScript
641
star
18

typescript

TypeScript Support for Nuxt 2
TypeScript
567
star
19

docs

Old Documentation of Nuxt.js ๐Ÿ’š - not in use anymore
539
star
20

learn.nuxt.com

[Work in Progress] An interactive tutorial and playground for Nuxt
Vue
492
star
21

starter

Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
382
star
22

eslint-config

ESlint config used for Nuxt
JavaScript
346
star
23

fonts

Plug-and-play web font optimization and configuration for Nuxt apps.
TypeScript
345
star
24

test-utils

๐Ÿงช Test utilities for Nuxt
TypeScript
273
star
25

assets

๐ŸŽจ Unified Assets and Templates for Nuxt
HTML
267
star
26

bridge

๐ŸŒ‰ Experience Nuxt 3 features on existing Nuxt 2 projects
TypeScript
263
star
27

nuxt.com

The Nuxt website, made with Nuxt.
Vue
225
star
28

nuxt.new

Create a new Nuxt project from your address bar.
Vue
225
star
29

http

Universal HTTP Module for Nuxt.js
JavaScript
221
star
30

cli

โšก๏ธ Nuxt Generation CLI Experience.
TypeScript
207
star
31

nitro-demo

nuxt nitro preview
Vue
187
star
32

telemetry

Nuxt Telemetry
TypeScript
185
star
33

press

[Deprecated] Minimalist Markdown Publishing for Nuxt.js
JavaScript
184
star
34

todomvc

Nuxt.js TodoMVC Example
Vue
146
star
35

examples

Deployed Nuxt examples
TypeScript
134
star
36

eslint-plugin-nuxt

ESLint plugin for Nuxt.js [WIP]
JavaScript
129
star
37

nuxters

Vue
124
star
38

rfcs

RFCs for changes to Nuxt.js
97
star
39

loading-screen

Loading Screen Module for Nuxt.js
JavaScript
90
star
40

scripts

Plug-and-play script optimization for Nuxt applications. (Public Preview)
TypeScript
65
star
41

cli-draft

WIP: CLI for Nuxt.js projects
62
star
42

postcss8

Opt-in to postcss 8 in Nuxt 2 apps.
TypeScript
58
star
43

actions-yarn

Github Actions for yarn
Shell
47
star
44

codesandbox-nuxt

Starter template for CodeSandBox.io
Vue
43
star
45

blueprints

Module for Nuxt.js to create distributable micro-apps
JavaScript
41
star
46

benchmarks

๐Ÿ’จ Nuxt.js SSR performance Benchmarks
JavaScript
24
star
47

renovate-config-nuxt

Nuxt.js presets for Renovate tool.
18
star
48

nuxt-services-experimental

[WIP] Around realtime services for Nuxt 3
JavaScript
17
star
49

nuxt3-stubs

JavaScript
13
star
50

static

Fast Static Builder
TypeScript
12
star
51

governance

Nuxt Project Governance
12
star
52

babel-preset-app

PSA: this repo has been moved into nuxt.js/nuxt --> https://github.com/nuxt/nuxt.js/tree/dev/packages/babel-preset-app
JavaScript
10
star
53

nuxt-redirects

Nuxt.js redirects app for Netlify
9
star
54

.github

Default community health files for nuxt repositories
4
star