discussions-and-proposals icon indicating copy to clipboard operation
discussions-and-proposals copied to clipboard

How safe is using Metro cache in Release builds?

Open ivanmoskalev opened this issue 4 years ago • 0 comments

Currently every Release build in iOS and Android invokes Metro bundler with --reset-cache to make a clean build. This becomes problematic when there are several 'flavors' that need to be built consecutively – probably the largest chunk of build time is spent in Metro. We actually have configured a custom cache store + a rolling cache on CI and it seems to work well.

const { FileStore } = require('metro-cache');

const CACHE_DIR = path.resolve(__dirname, '.metro/cache');

class NonResetCacheStore extends FileStore {
  clear() { /* Don't */ }
}

module.exports = (async () => {
  return {
    cacheStores: [
      new NonResetCacheStore({
        root: CACHE_DIR,
      }),
    ],
    // ...
})();

However, I'm not entirely sure this will not break in some subtle way (like, using a stale artifact for some module or producing an invalid sourcemap).

Question is: how safe is using a rolling Metro cache for production builds? Does Facebook use any sort of caching for React Native bundles internally? (there seems to be some code for distributed caching in the Metro OSS repo.)

ivanmoskalev avatar Jan 16 '21 07:01 ivanmoskalev