#How to tell vite the dynamic import will resolve post build?

1 messages · Page 1 of 1 (latest)

lofty pine
#

I am using pagefind (https://pagefind.app/), pagefind just crawls your static build and generates some code that you can use to query your build output (anchor tags, headers, etc).
Because pagefind will generate their js file only once the build is done the pagefind.js file is not present during the build so vite complains:

[vite:load-fallback] Could not load C:\Users\hugok\Documents\Work\Halloy\Halloy Docs\src\lib/../../static/_pagefind/pagefind.js (imported by src/lib/pagefind/pagefind.ts): ENOENT: no such file or directory, open 'C:\Users\hugok\Documents\Work\Halloy\Halloy Docs\static\_pagefind\pagefind.js'   
error during build:
Error: Could not load C:\Users\hugok\Documents\Work\Halloy\Halloy Docs\src\lib/../../static/_pagefind/pagefind.js (imported by src/lib/pagefind/pagefind.ts): ENOENT: no such file or directory, open 'C:\Users\hugok\Documents\Work\Halloy\Halloy Docs\static\_pagefind\pagefind.js'ELIFECYCLECommand failed with exit code 1.

Can I somehow supress or disable this for a specific dynamic import?

sharp wharf
#

Mark pagefind.js as an external?

lofty pine
#

I only use vite in conjunction with other tools, I don’t know much about vite

sharp wharf
#

Ok, then I guess it is time to learn. Vite uses rollup. Rollup has this feature where you can say external: ["C:\Users\hugok\Documents\Work\Halloy\Halloy Docs\static_pagefind\pagefind.js"] and then Vite/rollup won't try to bundle it.

export default defineConfig({
  rollupOptions: {
    build: {
      external: ["C:\Users\hugok\Documents\Work\Halloy\Halloy Docs\static\_pagefind\pagefind.js"
    }
  }
});
#

Or something like that. I wrote it without looking for it. Hoping the path is right.