npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@organisme/nuxt

v0.5.0

Published

Nuxt package of Organisme.

Downloads

2

Readme

📦 Nuxt Module Builder

Complete solution to build Nuxt Modules.

Features

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

Learn More

Check the new Guide for Nuxt Modules before starting with module-builder.

Requirements

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

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

Quick start

You can quickly get started with the pre-configured module starter:

$ npx nuxi init -t module my-module

Project structure

Using module builder, requires a special project setup. You can check an example here.

src/module.ts

This is 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 (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using yarn install
  • Try building example module using yarn example:build

License

MIT - Made with 💚