The existing implementation of the getData and fetchData methods in config/data.js are somewhat broken, because they don't work inside the vite build: they presume the local files are available to read (as they are when you run npm run data) — but this breaks inside CircleCI or npm run build after the Vite build finishes.
This update tweaks the loading script to ensure those functions always run within the vite context, allowing them to use dynamic import() statement and reference Vite helpers like import.meta.glob like any other script. This makes the script much more isomorphic, so that it works either via the CLI command (npm run data) or during the build phase (npm run build).
As before, template users should continue to add their own custom data-fetching code inside config/data.js -> fetchData(). By default, this function is run every time the page builds — but if a user runs npm run data, the output of that method will be cached within config/data.json and future builds will skip the live fetch.
The existing implementation of the
getData
andfetchData
methods inconfig/data.js
are somewhat broken, because they don't work inside the vite build: they presume the local files are available to read (as they are when you runnpm run data
) — but this breaks inside CircleCI ornpm run build
after the Vite build finishes.This update tweaks the loading script to ensure those functions always run within the vite context, allowing them to use dynamic
import()
statement and reference Vite helpers likeimport.meta.glob
like any other script. This makes the script much more isomorphic, so that it works either via the CLI command (npm run data
) or during the build phase (npm run build
).As before, template users should continue to add their own custom data-fetching code inside
config/data.js -> fetchData()
. By default, this function is run every time the page builds — but if a user runsnpm run data
, the output of that method will be cached withinconfig/data.json
and future builds will skip the live fetch.