As we have mentioned already, modules are functions, and they can be optionally packaged as npm modules. This is the very basic structure you need to create a module:
// modules/basic.js
export default function (moduleOptions) {
// ....
}
You just need to create a /modules/ directory in your project root and then start writing the code for your module. Note that you must include this following line if you want to publish your module as an npm package:
module.exports.meta = require('./package.json')
If you want to create the module and publish it as an npm package, follow this template from the Nuxt community:
https://github.com/nuxt-community/module-template/tree/master/template
Whether you are creating a module for the Nuxt community or your own project only, each module can access the following things:
- The module options:
We can pass some options in a JavaScript object to the module from the config file, for example:
// nuxt.config.js
export...