linaria
linaria copied to clipboard
Record "requiredFiles" in babel result, for cache key purposes
Describe the feature
Add "requiredFiles" to the babel result, that lists the file paths + hashes of each file that gets used in static evaluation.
Motivation
Something we've done and found useful is recording the files that get required during static evaluation in the babel result (the paths, and the sha1 of each file). This is useful as it lets us cache the result of transforms, and know when to bust this cache too. We're using metro as our build system, which has a per-file cache for transformations. This means that a file like this:
import { constant } from './file';
css`
background: ${constant}
`;
that we need to bust the cache if the constant
changes.
Possible implementations
We figured this out on the version of linaria we're on, in module.ts
(at least in the version we're on, I'm sure this is possible in the latest linaria, too)
const requiredFile = {
file: path.relative(id, filename),
sha1: hashString(code)
};
this.requiredFiles.push(requiredFile);