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/dev/mock-dir.md.
  • 简体中文
  • dev.mockDir

    • 类型: string
    • 默认值: './config/mock'

    设置 Mock API 入口文件所在的目录。相对路径基于应用目录解析,同时也支持绝对路径。 开发环境下,Modern.js 会加载该目录中的 index.ts 或 index.js。

    例如,将 Mock API 入口移动到 mocks/index.ts:

    modern.config.ts
    import { defineConfig } from '@modern-js/app-tools';
    
    export default defineConfig({
      dev: {
        mockDir: './mocks',
      },
    });

    在 Monorepo 中,也可以让多个应用指向一个共享的 Mock 目录:

    modern.config.ts
    export default defineConfig({
      dev: {
        mockDir: '../../shared/mocks',
      },
    });