diff --git a/src/location.ts b/src/location.ts index 1bd34a52..e8faa3a7 100644 --- a/src/location.ts +++ b/src/location.ts @@ -1,3 +1,4 @@ +/// import type { RefWithScroll, ScrollName } from './ref.ts' type AppleSauce = { @@ -8,9 +9,16 @@ type AppleSauce = { type TOC = Record>> export async function loadScroll(name: ScrollName) { - const toc = await import(`./data/tables-of-contents/${name}.json`, { - with: { type: 'json' }, - }) + // TODO(https://github.com/vitejs/vite/issues/18582): Delete this workaround. + let toc + if (import.meta.env?.MODE) + // Vite dynamic imports doesn't support the second parameter + toc = await import(`./data/tables-of-contents/${name}.json`) + else + toc = await import(`./data/tables-of-contents/${name}.json`, { + // Node.js requires the second parameter. + with: { type: 'json' }, + }) return new ScrollResolver(name, toc.default) } diff --git a/src/view-model/scroll-view-model.ts b/src/view-model/scroll-view-model.ts index c4813875..25b08550 100644 --- a/src/view-model/scroll-view-model.ts +++ b/src/view-model/scroll-view-model.ts @@ -198,17 +198,24 @@ export abstract class ScrollViewModel { if (typeof pageNumber === 'object') return pageNumber if (!pageNumber || pageNumber <= 0) return null - const page: LineType[] = ( - await import( + + let page: { default: LineType[] } + if (import.meta.env?.MODE) + // Vite dynamic imports doesn't support the second parameter + page = await import( + `../data/pages/${this.relevantRuns[0].scroll}/${pageNumber}.json` + ) + else + page = await import( `../data/pages/${this.relevantRuns[0].scroll}/${pageNumber}.json`, + // Node.js requires the second parameter. { with: { type: 'json' } } ) - ).default let run: LeiningRun | undefined let aliyot: LeiningAliyah[] = [] const labeller = new AliyahLabeller() - const lines: RenderedLineInfo[] = page.map((rawLine) => { + const lines: RenderedLineInfo[] = page.default.map((rawLine) => { const verses = rawLine.verses.map(toRef) if (verses.length) [run, aliyot] = this.findContainingAliyot(verses, run)