Using Plugins

To use a plugin, you can configure it in the config file:

// poi.config.js
module.exports = {
  plugins: [
    {
      resolve: '@poi/plugin-typescript',
      options: {}
    }
  ]
}
  • resolve: A plugin package name or the path to it.
  • options: Optionally pass options to this plugin.

When options is not needed, you can simply use a string:

// poi.config.js
module.exports = {
  plugins: [
    '@poi/plugin-typescript',
    '../path/to/my/local/plugin'
  ]
}

Naming Convention

Official plugins are published under @poi org on npm, like the @poi/plugin-typescript plugin.

Community plugins must follow the poi-plugin-xxx or @org/poi-plugin-xxx naming convention.

Plugin Short-hand

For official plugins, i.e. published under @poi org on npm:

module.exports = {
  plugins: [
    {
      // equivalent to`@poi/plugin-typescript`
      resolve: '@poi/typescript'
    }
  ]
}

For community plugins, i.e. the name starts with poi-plugin-:

module.exports = {
  plugins: [
    {
      // equivalent to`poi-plugin-foo`
      resolve: 'foo'
    }
  ]
}

This also works with community scoped packages:

module.exports = {
  plugins: [
    {
      // equivalent to`@org/poi-plugin-foo`
      resolve: '@org/foo'
    }
  ]
}

Creating A Plugin

A plugin for Poi is an object which consists of following properties:

  • name: Plugin name.
  • cli: Optional. A method that is used to extend CLI.
  • apply: Optional. A method that is used to extend core API.
  • filterPlugins: Optional. A method that is used to remove exiting plugins or add new plugins.

apply and cli methods accept two arguments:

  • api: The Poi instance.
  • options: The options that is passed to this plugin from config file.
exports.name = 'my-plugin'

exports.apply = (api, options = {}) => {
  api.hook('createWebpackChain', config => {
    config.resolve.alias.add('.mdx')
  })
}
Last Updated: 1/23/2019, 1:19:28 PM