Laravel-mix: js + sass + copy = watch/compile loop

Created on 7 Feb 2017  路  14Comments  路  Source: JeffreyWay/laravel-mix

Hi

It seems that using mix.js() + mix.sass() + mix.copy() causes npm run watch to keep compiling.

Here's the code I'm using:

    .js('./resources/assets/js/nebula.js', './js')
    .sass('./resources/assets/sass/nebula.scss', './css')
    .copy('./js/nebula.js', '../../../public/vendor/nebula.js')
    .copy('./css/nebula.css', '../../../public/vendor/nebula.css')

I'm running mix inside a packages/vendor/name folder, so not in the project's route.

When I run npm run watch my console gets crazy and the only things I can see are

WAIT: compiling...
WAIT: Compiled successfully in Nms
WAIT: compiling...
WAIT: Compiled successfully in Nms
WAIT: compiling...
WAIT: Compiled successfully in Nms
WAIT: compiling...
WAIT: Compiled successfully in Nms

and so on.

Most helpful comment

I am also seeing this issue on a brand new install of Laravel 5.4 but without even running the copy command. My mix file is really simple:

mix.js('resources/assets/js/main.js', 'public/js')
    .sass('resources/assets/sass/app.scss', 'public/css');

I have commented out both parts in turn and it's the processCssUrls part of the sass script that causes the loop. If I comment out the background definition here:

body {
  background: url('images/bg-widescreen.jpg') no-repeat;

Then it compiles with no issues. Also if I change the mix file to:

mix.js('resources/assets/js/main.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .options({ processCssUrls: false });

It compiles with no issues.

All 14 comments

I'm not sure. Can you break it down and give me simple reproducible steps?

I had the same with the .sass, trying to debug now.

This might solve your issue @nicgutierrez https://github.com/JeffreyWay/laravel-mix/issues/228

thanks @nickkuijpers , I'll look into it :)

I too am having this problem when developing a package and wanting to automatically copy the compiled assets to the app's public/vendor folder.

I have tried the response to issue #228 but it didn't help. @nicgutierrez did you manage to fix it?

It's some package that you removed but left in the webpack.mix.js that causes this (not all the time). I had this issue before.

@ruchern I don't think it's that in my case.

This is my webpack.mix.js

const { mix } = require('laravel-mix');

mix.setPublicPath(__dirname + "/public");
mix.setResourceRoot(__dirname + "/resources");

mix.js('resources/assets/js/app.js', 'js')
    .sass('resources/assets/sass/app.scss', 'css')
    .copy('resources/assets/images', 'public/images', false);

if (mix.config.inProduction) {
    mix.version();
}

mix.copy('public', '../../../public/vendor/my_package', false);

Try placing that last line of copy before any compiling?

And for directories, use the mix.copyDirectory() helper.

I would need to compile them before copying though...

When I remove the copy line, it doesn't infinite loop, weird.

Try mix.copyDirectory() for last line. That looks like a directory to me. Assuming only.

copyDirectory doesn't work at all, I think it's documented incorrectly. That's why I included the false parameter.

I am also seeing this issue on a brand new install of Laravel 5.4 but without even running the copy command. My mix file is really simple:

mix.js('resources/assets/js/main.js', 'public/js')
    .sass('resources/assets/sass/app.scss', 'public/css');

I have commented out both parts in turn and it's the processCssUrls part of the sass script that causes the loop. If I comment out the background definition here:

body {
  background: url('images/bg-widescreen.jpg') no-repeat;

Then it compiles with no issues. Also if I change the mix file to:

mix.js('resources/assets/js/main.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .options({ processCssUrls: false });

It compiles with no issues.

@raffjones this worked for me
.options({ processCssUrls: false });
thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amin101 picture amin101  路  3Comments

RomainGoncalves picture RomainGoncalves  路  3Comments

pixieaka picture pixieaka  路  3Comments

nezaboravi picture nezaboravi  路  3Comments

dtheb picture dtheb  路  3Comments