Skip to content

Commit

Permalink
chore: update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Mar 2, 2023
1 parent 91b3dc7 commit 0f22ac3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
9 changes: 0 additions & 9 deletions src/features/derivative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,6 @@ export default (api: IApi) => {
USELESS_TMP_FILES.forEach((file) => {
fsExtra.rmSync(path.join(api.paths.absTmpPath, file), { force: true });
});

// replace @/loading from umi.ts, because dumi use `<rootDir>/.dumi` as absSrcPath
const umiPath = path.join(api.paths.absTmpPath, 'umi.ts');
fsExtra.writeFileSync(
umiPath,
fsExtra
.readFileSync(umiPath, 'utf-8')
.replace("'@/loading'", `'${api.appData.globalLoading}'`),
);
},
});

Expand Down
24 changes: 9 additions & 15 deletions src/features/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { IApi } from '@/types';
import { parseModuleSync } from '@umijs/bundler-utils';
import fs from 'fs';
import path from 'path';
import { deepmerge, lodash, winPath, glob, tryPaths, fsExtra } from 'umi/plugin-utils';
import { deepmerge, lodash, winPath } from 'umi/plugin-utils';
import { safeExcludeInMFSU } from '../derivative';
import loadTheme, { IThemeLoadResult } from './loader';

Expand Down Expand Up @@ -54,17 +54,6 @@ function getModuleExports(modulePath: string) {
})[1];
}

/**
* load loading component path
*/
function tryLoadLoadingPath(api: IApi) {
// .dumi/loading
const loadingComponent = tryPaths(
glob.sync('loading.{tsx,jsx,ts,js}', { cwd: api.paths.absSrcPath })
)
return loadingComponent ?? path.resolve(__dirname, '../../client/pages/Loading');
}

export default (api: IApi) => {
// load default theme
const defaultThemeData = loadTheme(DEFAULT_THEME_PATH);
Expand Down Expand Up @@ -150,8 +139,10 @@ export default (api: IApi) => {
});

api.modifyAppData((memo) => {
// The globalLoading in umi.js is a boolean value that we handle directly as the corresponding path
memo.globalLoading = tryLoadLoadingPath(api);
memo.globalLoading ??= path.resolve(
__dirname,
'../../client/pages/Loading',
);

return memo;
});
Expand All @@ -160,7 +151,10 @@ export default (api: IApi) => {
key: 'onGenerateFiles',
stage: -Infinity,
fn() {
api.appData.globalLoading ??= tryLoadLoadingPath(api);
api.appData.globalLoading ??= path.resolve(
__dirname,
'../../client/pages/Loading',
);
},
});

Expand Down

0 comments on commit 0f22ac3

Please sign in to comment.