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

fix: use define to inject SEARCH_WORKER_CODE instead of resourcequery dumi-raw #2161

Merged
merged 4 commits into from
Jul 4, 2024
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
5 changes: 2 additions & 3 deletions src/client/theme-api/useSiteSearch/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useNavData } from 'dumi';
import { useCallback, useEffect, useRef, useState } from 'react';
// @ts-ignore
import workerCode from '../../../../compiled/_internal/searchWorker.min?dumi-raw';
import useSearchData from './useSearchData';

export interface IHighlightText {
Expand Down Expand Up @@ -31,7 +29,8 @@ if (typeof window !== 'undefined') {
// use blob to avoid generate entry(chunk) for worker
worker = new Worker(
URL.createObjectURL(
new Blob([workerCode], { type: 'application/javascript' }),
// @ts-ignore
new Blob([SEARCH_WORKER_CODE], { type: 'application/javascript' }),
),
);
}
Expand Down
12 changes: 12 additions & 0 deletions src/features/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { IMdLoaderOptions } from '@/loaders/markdown';
import ReactTechStack from '@/techStacks/react';
import type { IApi, IDumiTechStack } from '@/types';
import { _setFSCacheDir } from '@/utils';
import fs from 'fs';
import path from 'path';
import { addAtomMeta, addExampleAssets } from '../assets';
import { getLoadHook } from './makoHooks';
Expand Down Expand Up @@ -35,6 +36,17 @@ export default (api: IApi) => {

if (cacheDirPath) _setFSCacheDir(path.join(cacheDirPath, 'dumi'));

Copy link
Member

@PeachScript PeachScript Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// inject raw code to use search worker in inline mode

// inject raw code to use search worker in inline mode
const SEARCH_WORKER_CODE = fs.readFileSync(
path.resolve(
__dirname,
'../../../compiled/_internal/searchWorker.min.js',
),
'utf-8',
);
memo.define ??= {};
memo.define.SEARCH_WORKER_CODE = SEARCH_WORKER_CODE;

return memo;
},
});
Expand Down
Loading