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] Files not being indexed during build #61

Merged
merged 2 commits into from
Mar 8, 2023
Merged
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
26 changes: 13 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from "vite";
import { Plugin, ResolvedConfig } from "vite";
import { IndexSearch } from "./md-index-builder";
import { Options } from "./types";

Expand All @@ -21,7 +21,8 @@ export function SearchPlugin(searchOptions?: Partial<Options>): Plugin {
...searchOptions,
};

let config: any;
let config: ResolvedConfig;
let computedIndex = false;
const virtualModuleId = "virtual:search-data";
const resolvedVirtualModuleId = "\0" + virtualModuleId;

Expand All @@ -44,18 +45,17 @@ export function SearchPlugin(searchOptions?: Partial<Options>): Plugin {
}
},
async load(this, id) {
if (id === resolvedVirtualModuleId) {
if (!config.build.ssr) {
//so we don't compute index search twice
let index = await IndexSearch(config.root, options);
return index;
}
return `const INDEX_DATA = { };
const PREVIEW_LOOKUP = {};
const Options = ${JSON.stringify(options)};
const data = { INDEX_DATA, PREVIEW_LOOKUP, Options };
export default data;`;
if (id !== resolvedVirtualModuleId) return;
if (!config.build.ssr || !computedIndex) {
//so we don't compute index search twice
computedIndex = true;
return await IndexSearch(config.root, options);
}
return `const INDEX_DATA = { };
const PREVIEW_LOOKUP = {};
const Options = ${JSON.stringify(options)};
const data = { INDEX_DATA, PREVIEW_LOOKUP, Options };
export default data;`;
},
};
}