docs/3.guide/4.modules/1.getting-started.md
We recommend you get started with Nuxt modules using our starter template:
::code-group{sync="pm"}
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.
::tip{icon="i-lucide-video" to="https://vueschool.io/lessons/navigating-the-official-starter-template?friend=nuxt" target="_blank"} Watch Vue School video about Nuxt module starter template. ::
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:build::note
All other nuxt 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:watch::tip Feel free to augment this default test strategy to better suit your needs. ::
Nuxt 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.
::tip
While building your module can be useful in some cases, most of the time you won't need to build it on your own: the playground takes care of it while developing, and the release script also has you covered when publishing.
::
::important
Before publishing your module to npm, makes sure you have an npmjs.com account and that you're authenticated to it locally with 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)::tip
As with other scripts, feel free to fine-tune the default release script in your package.json to better suit your needs.
::