v4 plugin migration: Enabling a plugin
This guide is part of the v4 plugin migration guide designed to help you migrate a plugin from Strapi v3.6.x to v4.0.x.
A Strapi v3 plugin was enabled if it was manually installed or found in the plugins
directory.
In Strapi v4:
- Installed plugins following the automatic plugins discovery pattern will automatically be enabled.
- While developing a local plugin, the plugin must explicitly be enabled in the
./config/plugins.js
file of the Strapi application.
To enable a local plugin in v4 and define an optional configuration:
If it does not already exist, create the
./config/plugins.js
file.In the
./config/plugins.js
file, export a function that:- returns an object
- and can take the
{Β env }
object as a parameter (see Environment configuration documentation).
Within the object exported by
./config/plugins.js
, create a key with the name of the plugin (e.g."my-plugin"
). The value of this key is also an object.Within the
"my-plugin"
object, set theenabled
key value totrue
(boolean).(optional) Add a
resolve
key, whose value is the path of the plugin folder (as a string), and aconfig
key (as an object) that can include additional configuration for the plugin (see plugins configuration documentation).
Example: Enabling and configuring a "my-plugin" plugin
module.exports = ({ env }) => ({
"my-plugin": {
enabled: true,
resolve: "./path-to-my-plugin",
config: {
// additional configuration goes here
},
},
});
If the plugin will be published on npm, the package.json
file should include a strapi.kind
key with a value set to "plugin"
(i.e. { "strapi": { "kind": "plugin" } }
).