For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/configure/app/plugins.md.
  • 简体中文
  • plugins

    • 类型: CliPlugin[]
    • 默认值: []

    用于配置自定义的 Modern.js 框架 CLI 插件。自定义 CLI 插件的编写方式请参考 如何编写 CLI 插件。

    注意事项

    该选项用于配置框架 CLI 插件,如果你需要配置其他类型的插件,请选择对应的配置方式:

    示例

    下面是 CLI 插件的使用示例。

    使用 npm 上的插件

    使用 npm 上的插件,需要通过包管理器安装插件,并通过 import 引入。

    modern.config.ts
    import { myPlugin } from 'my-plugin';
    
    export default defineConfig({
      plugins: [myPlugin()],
    });

    使用本地插件

    使用本地代码仓库中的插件,直接通过相对路径 import 引入即可。

    modern.config.ts
    import { myPlugin } from './config/plugin/myPlugin';
    
    export default defineConfig({
      plugins: [myPlugin()],
    });

    插件配置项

    如果插件提供了一些自定义的配置项,可以通过插件函数的参数传入配置。

    modern.config.ts
    import { myPlugin } from 'my-plugin';
    
    export default defineConfig({
      plugins: [
        myPlugin({
          foo: 1,
          bar: 2,
        }),
      ],
    });