We recommend you get started with Nuxt modules using our starter template:
npm create nuxt -- -t module my-module
yarn create nuxt -t module my-module
pnpm create nuxt -t module my-module
bun create nuxt --template=module my-module
This will create a my-module project with all the boilerplate necessary to develop and publish your module.
Next steps:
my-module in your IDE of choicenpm run dev:prepareLearn how to perform basic tasks with the module starter.
While your module source code lives inside the src directory, to develop a module you often need a Nuxt application to test it against. That's what the playground directory is for. It's a Nuxt application you can tinker with that is already configured to run with your module.
You can interact with the playground like with any Nuxt application.
npm run dev, it should reload itself as you make changes to your module in the src directorynpm run dev:buildnuxt commands can be used against the playground directory (e.g. nuxt <COMMAND> playground). Feel free to declare additional dev:* scripts within your package.json referencing them for convenience.The module starter comes with a basic test suite:
npm run lintnpm run test or npm run test:watchNuxt modules come with their own builder provided by @nuxt/module-builder. This builder doesn't require any configuration on your end, supports TypeScript, and makes sure your assets are properly bundled to be distributed to other Nuxt applications.
You can build your module by running npm run prepack.
playground takes care of it while developing, and the release script also has you covered when publishing.npm login.While you can publish your module by bumping its version and using the npm publish command, the module starter comes with a release script that helps you make sure you publish a working version of your module to npm and more.
To use the release script, first, commit all your changes (we recommend you follow Conventional Commits to also take advantage of automatic version bump and changelog update), then run the release script with npm run release.
When running the release script, the following will happen:
npm run lint)npm run test)npm run prepack)release script in your package.json to better suit your needs.