Laravel-mix: Laravel Mix is very slow when compiling sass files containing urls

Created on 3 Feb 2017  路  6Comments  路  Source: JeffreyWay/laravel-mix

Hello @JeffreyWay,
My app.scss file imports 6 other sass files. Typically, Laravel Mix compiles the whole thing in under 500ms, until I add a "background-image" property with a url to a local image to any of the elements in my files. Each time I add a url, the compilation time increases by about 3 seconds. In one of my files I had 3 urls to 3 background images, the compilation time was 9447ms. And once I removed all of them, the compilation time drops to around 500ms again. How can I fix this? I really appreciate the advice.

Most helpful comment

This issue has returned. Fast-sass-loader is no longer used it seems, however, this will fix it:

Mix.options({ processCssUrls: false });

All 6 comments

Duplicate of #232.

f5cb20274c24258dfb5c18741e627cc6235f03a6

@JeffreyWay boss, one more time. I want to separate file for production, dev and watch using some kind of condition for each npm run. For example,

npm run production
->
if(isCommand=='production'){ mix.js('resources/assets/js/app.js', 'public/js/app.min') .sass('resources/assets/sass/app.scss', 'public/css/app.min'); }

npm run watch
if(isCommand == 'dev' || isCommand == 'watch'){ mix.js('resources/assets/js/app.js', 'public/js/app') .sass('resources/assets/sass/app.scss', 'public/css/app'); }

This issue has returned. Fast-sass-loader is no longer used it seems, however, this will fix it:

Mix.options({ processCssUrls: false });

Woah!
From 30 seconds compile time to 300 milli seconds!!!!
Why isn't this documented anywhere (or am I just ignorant) ?

In case it helps anyone else, thought I'd extend this solution a bit. If you still need to process URLs for production, you can do this:

mix.sass('resources/sass/app.scss', 'public/css').options({
    processCssUrls: mix.inProduction()
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nezaboravi picture nezaboravi  路  3Comments

rlewkowicz picture rlewkowicz  路  3Comments

dtheb picture dtheb  路  3Comments

jpmurray picture jpmurray  路  3Comments

amin101 picture amin101  路  3Comments