Scaffolding a plugin
- New workspace
- Existing workspace
Plugin structure
After generation, the plugin folder contains:index.ts file is the plugin entry point registered in nx.json. Export createNodesV2 and createDependencies from this file to extend the project graph.
Adding generators and executors
Inferring tasks with createNodesV2
The most powerful feature of a plugin is the ability to automatically create tasks for any project that has a particular config file. This removes the need for users to manually define targets inproject.json.
Export createNodesV2 from your plugin’s index.ts:
Registering your plugin in nx.json
Add the plugin to theplugins array in nx.json. You can pass options that are forwarded to your createNodesV2 function:
Creating an init generator
If you create a generator namedinit, Nx runs it automatically when someone installs your plugin with nx add. Use it to register the plugin in nx.json:
Publishing a plugin to npm
1
Build the plugin
2
Update package.json
Make sure your
package.json has the correct name, version, main, generators, and executors fields:3
Publish to npm
4
Install in another workspace
init generator, it runs automatically.Testing your plugin
The plugin generator creates an e2e project alongside your plugin. Run it with:nx show project to inspect the computed project configuration:
