-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linaria Webpack loader cause rebuild twice for each change #878
Comments
For more context why this issue bother me, is because I'm developing a React-based project call GojiJS that use Linaria with Webpack as its CSS-in-JS solution ( docs ). This project runs not on browser but on a react-native-like environment called Mini Program. So hot reload is disabled. Each time developers changed a file, it cost twice times to rebuild the app. Since the simulator watched the So I believe this could be a performance issue, and once fixed, all Linaria apps could benefit. |
Hi @malash! Thank you for your report and for the suggested solution! Unfortunately, it seems like it breaks URLs in styles (eg. |
It looks too good to be true, but I slightly improved your suggestion and rewrote webpack loaders in a way how rollup loader was written: no css-files, only in-memory cache. And it works. No extra rebuilds, no problems with css-files and project roots, no transformations for URLs in CSS. |
Fixed in |
…ixes callstack#878) (callstack#879)" This reverts commit 5517cf7.
Environment
Description
In current implement,
linaria/loader
output a temp.css
file in.linaria-cache
while processing the JavaScript sources, and then append arequire('path/to/temp.linaria.css')
statement to it. Because Webpack always watches all the dependent files, it notice that temp.css
files are changed and should be rebuild.For a modification in dev mode, you can find the Webpack outputs
compiled successfully
twice:change a line of CSS in JS => recompile JS file => output temp CSS file => recompile CSS file
Solution
I believe inline matchResource could resolve this issue.
I'v created a temp bugfix here and it did works.
The conception of this solution is create a virtual
.css
file by inline match resource!=!
.For example,
is transformed to
Then, the
outputCssLoader
read the real.css
from itscssPath
option and return the code as a virtual.css
file ( the name before!=!
) to match the rules with/\.css$/
inwebpack.config.js
.According to Webpack dependent resolving logics, the
outputCssLoader
will recompile each time the.js
file changed, the watch mode should continue works.Reproducible Demo
Full reproducible demo here:
Linaria 2: https://github.com/malash/linaria-issue-878
Linaria 3: https://github.com/malash/linaria-issue-878/tree/linaria-3
Reproduce steps
yarn
yarn start
src/App.js
from
to
Compiled successfully
output twice, which means Webpack rebuild twice.Temporary fix
Un-comment this line in
webpack.config.js
to fix the issue:// { loader: require.resolve("./bugfix/replaceRequireRequestLoader") },
The text was updated successfully, but these errors were encountered: