Try   HackMD

HowTo: Patch Vite to expose Rollup cache

Goal is to access and use the Rollup cache between builds using Vite builder.build().

1. Find and patch the buildEnvironment function

(May be in node_modules/vite/dist/node/chunks/dep-M1IYMR16.js, or do a search in node_modules/vite/dist for async function buildEnvironment)

Make the following changes:

async function buildEnvironment(environment, rollupCache /* add this */) {
    if (rollupCache) { rollupOptions.cache = rollupCache; } // add this
    bundle = await rollup(rollupOptions);

And replace

    return Array.isArray(outputs) ? res : res[0];

with

    const returnValue = Array.isArray(outputs) ? res : res[0]
    returnValue.cache = bundle.cache
    return returnValue

2. Find and patch ViteBuilder.build

(May be in node_modules/vite/dist/node/chunks/dep-M1IYMR16.js, or do a search in node_modules/vite/dist for return buildEnvironment(environment))

Change it to:

    async build(environment, rollupCache) {
      return buildEnvironment(environment, rollupCache);
    }

References

Notes

  const rollupOptions = {
    preserveEntrySignatures: ssr ? "allow-extension" : libOptions ? "strict" : false,
    cache: rollupCache /* add this */ || options.watch ? undefined : false,
    ...options.rollupOptions,

The above isn’t working, rollupOptions.cache still seems to be false at the end. Probably options.rollupOptions is overriding it.