Home > Software engineering >  How to change babel-loader cache directory?
How to change babel-loader cache directory?

Time:10-30

I'm using react-app-rewired, here is my config-overrides.js:

const { getBabelLoader } = require('customize-cra');

module.exports = {
  webpack: (config, env) => {
    getBabelLoader(config).options.cacheDirectory = 'babel-cache';
    return config;
  }
};

I'm trying to change a babel-loader cache directory. babel-cache direcory is created, but its size is just 1.5 Mb. The size of node_modules/.cache/babel-loader is 106 Mb.

Is it possible to save cache into the specified folder only?

Actually I'm trying to improve performance of a continuous integration process. The problem is that npm ci command clears node_modules/.cache folder. And GitLab CI/CD builds the project from scratch. Maybe it's possible to keep node_modules/.cache somehow?

CodePudding user response:

You can't, at least not what I can tell from the docs. You'll have to create a feature request or post build script to move said cache.

According to the docs:

cacheDirectory: Default false. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is set to true in options ({cacheDirectory: true}), the loader will use the default cache directory in node_modules/.cache/babel-loader or fallback to the default OS temporary file directory if no node_modules folder could be found in any root directory.

So, it's either node_modules/.cache/babel-loader or the OS cache directory.

Maybe you can do something with a customer loader, but I don't know for sure.

  • Related