From 870b38affc305782ada6446fa339293c0588ddb0 Mon Sep 17 00:00:00 2001 From: Wuxh Date: Fri, 3 Mar 2023 09:47:37 +0800 Subject: [PATCH 1/3] refactor: site template ignore dist dir (#1518) add /dist > .gitignore --- suites/boilerplate/templates/site/.gitignore.tpl | 1 + 1 file changed, 1 insertion(+) diff --git a/suites/boilerplate/templates/site/.gitignore.tpl b/suites/boilerplate/templates/site/.gitignore.tpl index b1143cedcd..5a239de453 100644 --- a/suites/boilerplate/templates/site/.gitignore.tpl +++ b/suites/boilerplate/templates/site/.gitignore.tpl @@ -1,4 +1,5 @@ node_modules +/dist .dumi/tmp .dumi/tmp-production .DS_Store From bebc26dbe5464c69cd3cfb7cb09d8a3b1af0f45a Mon Sep 17 00:00:00 2001 From: Wuxh Date: Fri, 3 Mar 2023 10:07:24 +0800 Subject: [PATCH 2/3] refactor: improve content padding when disable footer (#1517) * chore(theme): improve the default theme style * chore: update Content style * chore: update --- .../theme-default/slots/Content/index.less | 16 ++++++++++++++++ src/client/theme-default/slots/Content/index.tsx | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/client/theme-default/slots/Content/index.less b/src/client/theme-default/slots/Content/index.less index 0f648dded3..cc89ebb089 100644 --- a/src/client/theme-default/slots/Content/index.less +++ b/src/client/theme-default/slots/Content/index.less @@ -158,12 +158,20 @@ background-color: lighten(@c-site-bg-dark, 3%); } + &[data-no-footer] { + padding-bottom: @s-content-padding; + } + @media @mobile { max-width: initial; margin: 0 -24px; padding: 24px 24px 0; border-radius: 0; box-shadow: none; + + &[data-no-footer] { + padding: 24px; + } } } @@ -175,4 +183,12 @@ min-height: calc(100vh - @s-header-height-m); } } + + &[data-no-sidebar][data-no-footer] { + margin-bottom: @s-content-padding; + + @media @mobile { + margin-bottom: 24px; + } + } } diff --git a/src/client/theme-default/slots/Content/index.tsx b/src/client/theme-default/slots/Content/index.tsx index ca266ce44e..1704fff827 100644 --- a/src/client/theme-default/slots/Content/index.tsx +++ b/src/client/theme-default/slots/Content/index.tsx @@ -1,15 +1,17 @@ -import { useSidebarData } from 'dumi'; +import { useSidebarData, useSiteData } from 'dumi'; import React, { type FC, type ReactNode } from 'react'; import './heti.scss'; import './index.less'; const Content: FC<{ children: ReactNode }> = (props) => { const sidebar = useSidebarData(); + const { themeConfig } = useSiteData(); return (
{props.children}
From edd743e6e65060fd74b2f5ed526cb526ca7d5357 Mon Sep 17 00:00:00 2001 From: Peach Date: Fri, 3 Mar 2023 10:23:18 +0800 Subject: [PATCH 3/3] refactor: make chunk name clean for theme routes (#1513) --- src/features/routes.ts | 30 ++++-------------------------- src/features/theme/index.ts | 14 ++++++++++---- src/utils.ts | 24 +++++++++++++++++++++++- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/features/routes.ts b/src/features/routes.ts index 2baee1703e..a730241e21 100644 --- a/src/features/routes.ts +++ b/src/features/routes.ts @@ -1,11 +1,12 @@ import { SP_ROUTE_PREFIX } from '@/constants'; import type { IApi } from '@/types'; +import { getClientDistFile } from '@/utils'; import { getConventionRoutes } from '@umijs/core'; import { createRouteId } from '@umijs/core/dist/route/utils'; import path from 'path'; import { plural } from 'pluralize'; import type { IRoute } from 'umi'; -import { glob, resolve, winPath } from 'umi/plugin-utils'; +import { glob, winPath } from 'umi/plugin-utils'; const CTX_LAYOUT_ID = 'dumi-context-layout'; @@ -89,29 +90,6 @@ function flatRoute(route: IRoute, docLayoutId: string) { } } -/** - * get page route file - */ -function getClientPageFile(file: string, cwd: string) { - let clientFile: string; - - try { - // why use `resolve`? - // because `require.resolve` will use the final path of symlink file - // and in tnpm project, umi will get a file path includes `@` symbol then - // generate a chunk name with `@` symbol, which is not supported by cdn - clientFile = resolve.sync(`dumi/dist/${file}`, { - basedir: cwd, - preserveSymlinks: false, - }); - } catch { - // fallback to use `require.resolve`, for dumi self docs & examples - clientFile = require.resolve(`../${file}`); - } - - return winPath(clientFile); -} - export default (api: IApi) => { const extraWatchPaths = [ ...(api.userConfig.resolve?.atomDirs || []), @@ -284,7 +262,7 @@ export default (api: IApi) => { path: '*', absPath: '/*', parentId: docLayoutId, - file: getClientPageFile('client/pages/404', api.cwd), + file: getClientDistFile('dist/client/pages/404', api.cwd), }; } @@ -294,7 +272,7 @@ export default (api: IApi) => { path: `${SP_ROUTE_PREFIX}demos/:id`, absPath: `/${SP_ROUTE_PREFIX}demos/:id`, parentId: demoLayoutId, - file: getClientPageFile('client/pages/Demo', api.cwd), + file: getClientDistFile('dist/client/pages/Demo', api.cwd), // disable prerender for demo render page, because umi-hd doesn't support ssr // ref: https://github.com/umijs/dumi/pull/1451 prerender: false, diff --git a/src/features/theme/index.ts b/src/features/theme/index.ts index 88b283beda..b4f069fa76 100644 --- a/src/features/theme/index.ts +++ b/src/features/theme/index.ts @@ -5,15 +5,14 @@ import { THEME_PREFIX, } from '@/constants'; import type { IApi } from '@/types'; +import { getClientDistFile } from '@/utils'; import { parseModuleSync } from '@umijs/bundler-utils'; import fs from 'fs'; import path from 'path'; -import { deepmerge, lodash, winPath } from 'umi/plugin-utils'; +import { deepmerge, lodash, resolve, winPath } from 'umi/plugin-utils'; import { safeExcludeInMFSU } from '../derivative'; import loadTheme, { IThemeLoadResult } from './loader'; -const DEFAULT_THEME_PATH = path.join(__dirname, '../../../theme-default'); - /** * get pkg theme name */ @@ -39,7 +38,10 @@ function getPkgThemePath(api: IApi) { return ( pkgThemeName && path.dirname( - require.resolve(`${pkgThemeName}/package.json`, { paths: [api.cwd] }), + resolve.sync(`${pkgThemeName}/package.json`, { + basedir: api.cwd, + preserveSymlinks: true, + }), ) ); } @@ -55,6 +57,10 @@ function getModuleExports(modulePath: string) { } export default (api: IApi) => { + const DEFAULT_THEME_PATH = path.join( + getClientDistFile('package.json', api.cwd), + '../theme-default', + ); // load default theme const defaultThemeData = loadTheme(DEFAULT_THEME_PATH); // try to load theme package diff --git a/src/utils.ts b/src/utils.ts index 207cd90ac5..61d8299b95 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,7 @@ import Cache from 'file-system-cache'; import fs from 'fs'; import yaml from 'js-yaml'; import path from 'path'; -import { lodash, logger, winPath } from 'umi/plugin-utils'; +import { lodash, logger, resolve, winPath } from 'umi/plugin-utils'; /** * get route path from file-system path @@ -158,3 +158,25 @@ export function getProjectRoot(cwd: string) { return winPath(cwd); } + +/** + * get dumi client dist file and preserve symlink(pnpm, tnpm & etc.) to make chunk name clean + */ +export function getClientDistFile(file: string, cwd: string) { + let clientFile: string; + + try { + // why use `resolve`? + // because `require.resolve` will use the final path of symlink file + // and in tnpm or pnpm project, the long realpath make chunk name unexpected + clientFile = resolve.sync(`dumi/${file}`, { + basedir: cwd, + preserveSymlinks: true, + }); + } catch { + // fallback to use `require.resolve`, for dumi self docs & examples + clientFile = require.resolve(`../${file}`); + } + + return winPath(clientFile); +}