laravel-mix: 'npm run watch' endless loop of rebuilding css
- Laravel Mix Version: laravel-mix@4.0.14
- Node Version: 10.15.0
- NPM Version: 6.4.1
- OS: Windows 10
Description:
Trying to compile an scss file, the watch task will build the css over and over multiple times per second.
Steps To Reproduce:
webpack.mix.js
let mix = require('laravel-mix');
mix.sass('resources/assets/sass/test.scss', 'public/css');
test.scss
@import 'test2';
@font-face {
font-family: 'Open Sans Light';
src: url('../fonts/open-sans-v15-latin-300.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
_test2.scss
/*
A
*/
Result:
10% building 1/1 modules 0 active
webpack is watching the files…
98% after emitting SizeLimitsPlugin DONE Compiled successfully in 1620ms12:08:58
Asset Size Chunks Chunk Names
/css/test.css 204 bytes mix [emitted] mix
fonts/open-sans-v15-latin-300.ttf?177cc92d2e8027712a8c1724abd272cd 27 KiB [emitted]
WAIT Compiling...12:08:58
98% after emitting SizeLimitsPlugin DONE Compiled successfully in 33ms12:08:58
Asset Size Chunks Chunk Names
/css/test.css 204 bytes mix [emitted] mix
fonts/open-sans-v15-latin-300.ttf?177cc92d2e8027712a8c1724abd272cd 27 KiB [emitted]
WAIT Compiling...12:08:58
98% after emitting SizeLimitsPlugin DONE Compiled successfully in 24ms12:08:59
Asset Size Chunks Chunk Names
/css/test.css 204 bytes mix [emitted] mix
fonts/open-sans-v15-latin-300.ttf?177cc92d2e8027712a8c1724abd272cd 27 KiB [emitted]
[... continuing forever]
The font file linked by url() exists and is copied as expected. Using a single line comment instead of a multiline comment in _test2.scss works as expected and does not exhibit this behavior. Moving the multiline comment to test1.scss and removing the @import works as expected, and removing the @font-face also prevents the loop. It’s the combination of @import, @font-face and the multiline comment in the imported file that cause the watch task to loop.
Needless to say, dev and prod tasks work perfectly fine, everything is compiled properly, no errors anywhere.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (1 by maintainers)
This solution makes it possible to continue using glob patterns even with Laravel Mix:
yarn add fast-glob -Dand thenIt works perfectly and solves the problem of the rebuild loop.
In case anyone wants to know I fixed this by installing node-sass and sass-loader
npm install node-sass sass-loaderFor those who currently switched to
Tailwind CSS V3and are uingjitmode this solution actually works. In my case I am using Laravel Jigsaw here is my tailwind.config.js fileif you put the image to
resources/imagesthey will be automatically copied to thepublic/imagesand there will be no loop present 😃 the same goes with the fontresources/fontscopied topublic/fontsThis issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue seems like it can have multiple error sources. In my case I it was relevant to Tailwind CSS and the
purgeoption. I don’t remember exactly what package I have installed but I copy pasted the following to mytailwind.config.js:After I have removed the line
'./public/**/*.html',it worked.credits to ** @Morpheus-ro** Don’t put any new files ( fonts or images ) in the public or dist folder … put them in your resources and the compiler will take care of copying them into your public folder …
@mostafa-A48 this solved it for me - thanks!
For anyone reading this using the ‘blog’ starter template with jigsaw, you also need to include
vueas an extension for the search component to work.my
tailwind.config.jsfile:The issue does not exist in
laravel-mix@3.0.0