Skip to content

Commit

Permalink
fix: use define to inject SEARCH_WORKER_CODE instead of resourcequery…
Browse files Browse the repository at this point in the history
… dumi-raw (#2161)

* fix: dumi-raw error
* chore: revert code
  • Loading branch information
Jinbao1001 authored Jul 4, 2024
1 parent 6d8e479 commit c4dbce1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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'));

// 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

0 comments on commit c4dbce1

Please sign in to comment.