Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加 conventionLayout 配置,可通过 false 关闭约定 layout #11137

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/docs/api/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ depPerChunk 和 bigVendors 类似,不同的是把依赖按 package name + vers

granularChunks 在 bigVendors 和 depPerChunk 之间取了中间值,同时又能在缓存效率上有更好的利用。无特殊场景,建议用 granularChunks 策略。

## conventionLayout

- 类型:`boolean`
- 默认值:`undefined`

`src/layouts/index.[tsx|vue|jsx|js]` 为约定式布局,默认开启。可通过配置 `conventionLayout: false` 关闭该默认行为。

## conventionRoutes

- 类型:`{ base: string; exclude: RegExp[] }`
Expand Down
1 change: 1 addition & 0 deletions packages/preset-umi/src/features/configPlugins/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function getSchemas(): Record<string, ({}: { zod: typeof z }) => any> {
return {
analyze: ({ zod }) => zod.object({}),
base: ({ zod }) => zod.string(),
conventionLayout: ({ zod }) => zod.boolean(),
hanzebang marked this conversation as resolved.
Show resolved Hide resolved
conventionRoutes: ({ zod }) =>
zod.object({
base: zod.string().optional(),
Expand Down
15 changes: 9 additions & 6 deletions packages/preset-umi/src/features/tmpFiles/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ export async function getRoutes(opts: {
}

// layout routes
const absLayoutPath = tryPaths([
join(opts.api.paths.absSrcPath, 'layouts/index.tsx'),
join(opts.api.paths.absSrcPath, 'layouts/index.vue'),
join(opts.api.paths.absSrcPath, 'layouts/index.jsx'),
join(opts.api.paths.absSrcPath, 'layouts/index.js'),
]);
const absLayoutPath =
opts.api.config?.conventionLayout === false
? false
: tryPaths([
join(opts.api.paths.absSrcPath, 'layouts/index.tsx'),
join(opts.api.paths.absSrcPath, 'layouts/index.vue'),
join(opts.api.paths.absSrcPath, 'layouts/index.jsx'),
join(opts.api.paths.absSrcPath, 'layouts/index.js'),
]);

const layouts = await opts.api.applyPlugins({
key: 'addLayouts',
Expand Down