Plugins development
Strapi allows the development of local plugins that work exactly like the external plugins available from the Marketplace.
If you would rather extend an existing plugin than create a new one, see the Plugins extension documentation.
Create a plugin
Strapi provides a command line interface (CLI) for creating plugins. To create a plugin:
- Navigate to the root of a Strapi project.
- Run
yarn strapi generateornpm run strapi generatein a terminal window to start the interactive CLI. - Choose "plugin" from the list, press Enter, and give the plugin a name in kebab-case (e.g.
my-plugin) - Choose either
JavaScriptorTypeScriptfor the plugin language. - Create a plugins configuration file if one does not already exist:
./config/plugins.jsor./config/plugins.tsfor TypeScript projects. - Enable the plugin by adding it to the plugins configurations file:
- JavaScript
- TypeScript
module.exports = {
// ...
'my-plugin': {
enabled: true,
resolve: './src/plugins/my-plugin' // path to plugin folder
},
// ...
}
export default {
// ...
'my-plugin': {
enabled: true,
resolve: './src/plugins/my-plugin' // path to plugin folder
},
// ...
}
- Run
npm installoryarnin the newly-created plugin directory. - (TypeScript-specific) Run
yarn buildornpm run buildin the plugin directory. This step transpiles the TypeScript files and outputs the JavaScript files to adistdirectory that is unique to the plugin. - Run
yarn buildornpm run buildat the project root. - Run
yarn developornpm run developat the project root.
Plugins created using the preceding directions are located in the plugins directory of the application (see project structure).
During plugin development it is helpful to use the --watch-admin flag to toggle hot reloading of the admin panel. See the Admin panel customization documentation for more details. (TypeScript specific) While developing your plugin, you can run yarn develop --watch-admin or npm run develop -- --watch-admin in the plugin directory to watch the changes to the TypeScript server files.
Check this blog post to learn how to publish your Strapi plugin on npm.
Add features to a plugin
Strapi provides programmatic APIs for plugins to hook into some of Strapi's features.
Plugins can register with the server and/or the admin panel, by looking for entry point files at the root of the package:
strapi-server.jsfor the Server (see Server API),strapi-admin.jsfor the admin panel (see Admin Panel API).
Plugins can also be used to add custom fields to Strapi.