In-memory cache isn't compatible with thread-loader #881
Labels
bug report 🦗
Issue is probably a bug, but it needs to be checked
bundler: webpack 📦
Issue is related to webpack bundler
cat: performance 🚀
Issue is related to performance
needs: complete repro 🖥️
Issue need to have complete repro provided
Environment
Description
The PR #879 introduced an in-memory cache to fix rebuild issue and accelerate bundle time. It's awesome, but when I try to integrate the latest version of Linaria in my project, I found some output CSS code is missing.
I deep dived and realize the in-memory cache may not be compatible with thread-loader.
thread-loader
use a thread poll to execute loaders in non-main threads, which can hugely speed up Webpack's building time in a large project. Since the threads in NodeJS cannot share the same closure context, the cssLookup map could be empty when runningoutputCssLoader.ts
in a brand new thread.I'm not sure is this a bug or a feature request? because not all Webpack projects use the
thread-loader
. But in our project, the build time would become non-acceptable if I disabled thethread-loader
. So I can provide a posable solution if you agree to fix this issue:Solution
Add a new options to return the right of choice to Linaria users.
cacheType: 'memory' | 'filesystem'
(default:'memory'
):This option is inspired from Webpack's cache.type. If set to
memory
the loader works in the same way as 2.2.0, and if set tofilesystem
it works in the same way as 2.1.0.cacheDirectory: string
(default:'.linaria-cache'
):Same as previous. Only works when
cacheType: 'filesystem'
Reproducible Demo
https://github.com/malash/linaria-issue-881
You can enable/disable this line and run
yarn webpack
, the check the result ofdist/styles.css
.The text was updated successfully, but these errors were encountered: