Skip to content

Commit

Permalink
refactor: output scp to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Jan 26, 2024
1 parent 1eba01f commit aba626e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
8 changes: 2 additions & 6 deletions packages/preset-umi/.fatherrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ export default defineConfig({
cjs: {
ignores: ['src/client/*'],
},
esm: {
ignores: ['!src/client/prefetchRouteFiles.ts'],
output: 'dist',
},
umd: {
entry: 'src/client/prefetchRouteFilesScp.ts',
output: 'compiled/prefetchRouteFilesScp',
output: 'templates/routePrefetch',
chainWebpack(memo) {
memo.output.filename('index.js');
memo.output.filename('prefetchRouteFilesScp.js');
memo.output.delete('libraryTarget');
memo.output.iife(true);

Expand Down
2 changes: 1 addition & 1 deletion packages/preset-umi/src/client/prefetchRouteFilesScp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* NOTE: DO NOT USE ADVANCED SYNTAX IN THIS FILE, TO AVOID INSERT HELPERS TO REDUCE SCRIPT SIZE.
*/

import prefetchRouteFiles from './prefetchRouteFiles';
import prefetchRouteFiles from '../features/routePrefetch/prefetchRouteFiles';

const basename = '{{basename}}';
const publicPath = '{{publicPath}}';
Expand Down
1 change: 0 additions & 1 deletion packages/preset-umi/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export const DEFAULT_PORT = '8000';
export const DEFAULT_HOST = '0.0.0.0';
export const CACHE_DIR_NAME = '.cache';
export const TEMPLATES_DIR = join(__dirname, '../templates');
export const PREFETCH_ROUTE_MAP_SCP_TYPE = 'umi-route-chunk-files-map';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* NOTE: DO NOT USE ADVANCED SYNTAX IN THIS FILE, TO AVOID INSERT HELPERS TO REDUCE SCRIPT SIZE.
*/

import type { IRouteChunkFilesMap } from '../features/routePrefetch/routePrefetch';
import type { IRouteChunkFilesMap } from './routePrefetch';

export const PREFETCH_ROUTE_MAP_SCP_TYPE = 'umi-route-chunk-files-map';

function prefetchRouteFiles(
path: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { lodash, logger, winPath } from '@umijs/utils';
import assert from 'assert';
import { readFileSync, writeFileSync } from 'fs';
import { dirname, isAbsolute, join, relative } from 'path';
import { PREFETCH_ROUTE_MAP_SCP_TYPE } from '../../constants';
import { TEMPLATES_DIR } from '../../constants';
import { createResolver } from '../../libs/scan';
import type { IApi, IRoute } from '../../types';
import { PREFETCH_ROUTE_MAP_SCP_TYPE } from './prefetchRouteFiles';

export interface IRouteChunkFilesMap {
/**
Expand Down Expand Up @@ -102,7 +103,7 @@ export default (api: IApi) => {
[
{
content: readFileSync(
require.resolve('../../../compiled/prefetchRouteFilesScp'),
join(TEMPLATES_DIR, 'routePrefetch/prefetchRouteFilesScp.js'),
'utf-8',
)
.replace(
Expand Down

0 comments on commit aba626e

Please sign in to comment.