plugins

  • Type: RuntimePlugin[]
  • Default: []

Used to configure custom Modern.js Runtime plugins. For details on how to create custom Runtime plugins, please refer to How to Write Runtime Plugins.

INFO

Runtime plugins must be configured in the plugins array within the src/modern.runtime.ts file.

Examples

Here are examples demonstrating how to use Runtime plugins:

Using plugins from npm packages

To use plugins published on npm, first install them via your package manager, then import them into your configuration.

src/modern.runtime.ts
import { defineRuntimeConfig } from '@modern-js/runtime';
import { myPlugin } from 'my-plugin';

export default defineRuntimeConfig({
  plugins: [myPlugin()],
});

Using local plugins

To use plugins from your local codebase, import them directly using relative paths.

src/modern.runtime.ts
import { defineRuntimeConfig } from '@modern-js/runtime';
import { myPlugin } from './config/plugin/myPlugin';

export default defineRuntimeConfig({
  plugins: [myPlugin()],
});

Plugin configuration

If a plugin supports custom configuration options, you can provide them as arguments to the plugin function.

src/modern.runtime.ts
import { defineRuntimeConfig } from '@modern-js/runtime';
import { myPlugin } from './config/plugin/myPlugin';

export default defineRuntimeConfig({
  plugins: [myPlugin({
    foo: 1,
    bar: 2,
  })],
});