跳转到主文档

output.titleByEntries

  • 类型: Object
  • 默认值: undefined

用于在多页面的场景下,为不同的页面设置不同的 title

整体用法与 output.title 一致,主要区别在于,可以使用「入口名称」作为 key 进行单独设置。

入口名称

默认情况下,「入口名称」为页面入口所在目录的名称。

例如,项目的目录结构如下时,入口名称为 page-apage-b

└── src
├── page-a
│   └── App.jsx
└── page-b
└── App.jsx

如果使用 source.entries 自定义了页面入口,则「入口名称」为 source.entries 对象的 key

示例

modern.config.js
import { defineConfig } from '@modern-js/app-tools';

export default defineConfig({
output: {
title: '今日头条',
titleByEntries: {
'page-a': '抖音',
},
},
});

可以看到入口 page-atitle 值为「 抖音 」,

其他入口,如 page-btitle 会被设置为 output.title 即「 今日头条 」。