Skip to content

Commit

Permalink
Merge pull request #61 from JeanJPNM/fix-indexing-on-build
Browse files Browse the repository at this point in the history
[fix] Files not being indexed during build
  • Loading branch information
emersonbottero authored Mar 8, 2023
2 parents 789167b + 3b01632 commit a82df90
Showing 1 changed file with 13 additions and 13 deletions.
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;`;
},
};
}

0 comments on commit a82df90

Please sign in to comment.