Laravel-mix: laravel mix didn't delete previous versions of files when i watch it

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

"devDependencies": {
"axios": "^0.15.3",
"bootstrap-sass": "^3.3.7",
"jquery": "^3.1.1",
"laravel-mix": "^0.7.2",
"lodash": "^4.17.4",
"vue": "^2.1.10"
}

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

capture
capture2

Most helpful comment

Yeah - when running the watcher, it wasn't updating the manifest cache properly. I've fixed that now.

All 35 comments

Yes I have the same issue on Windows 10. Watching from within the virtual machine or from Windows both have the same result.

jway has said that he doesn't want mix to delete files. that should be a more deliberate action taken by the user. [edit: I stand corrected. I was thinking of this post by jway, but as noted below, version() does try to delete old files]

but version() should only be run when creating a production build imo, so maybe the version method in mix should be refactored.

It looks like it does try to delete the old version but this is either not being run or some issue with what it's trying to do.

https://github.com/JeffreyWay/laravel-mix/blob/master/src/Versioning.js#L31

I can confirm this bug in my environment as well. Hoping for a fix.

The path to the files in the mix-manifest.json is changed over the latest version so perhaps there are some conflicts there?

Sure! You don麓t have to do something special, though:

New project/folder:

  1. npm init -y
  2. npm install laravel-mix --save-dev
  3. cp node_modules/laravel-mix/setup/webpack.mix.js .
  4. mkdir src
  5. create the files app.js and app.scss with some small content like let a=0; and .test { font-weight: bold; }.
  6. Add the scripts to package.json, eg:
  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development webpack --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hmr": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "cross-env NODE_ENV=production webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  1. Activate version inside webpack.mix.js like:
mix.js('src/app.js', 'dist/')
   .sass('src/app.scss', 'dist/')
   .version();
  1. Enable the watch operation, npm run watch
  2. Now change either the app.js or app.scss and watch the dist folder grow for each change.

Yeah - when running the watcher, it wasn't updating the manifest cache properly. I've fixed that now.

It works great thanks for great support.

Doesn't seem to remove previous version files for me - just installed the package and it generates new one, but leaves the old one in the output directory. Any idea?

@JeffreyWay - any update please?

@sebastiansulinski what Laravel Mix version are you using?

Latest "laravel-mix": "^0.10.0" and my mix is:

mix
    .js('./resources/js/app.js', 'public/js/')
    .sass('./resources/scss/app.scss', 'public/css/')
    .sourceMaps()
    .version();

Can you try removing .sourceMaps() to see whether you still receive the issue please?

Just tried - no difference I'm afraid.

Is this on a local development or on a hosted server?

It's local - I'm using homestead with standalone laravel-mix (non-laravel project).

Okay and are you running npm run watch from inside Homestead or outside?

No - I'm running it manually (without watch - simply npm run dev) and it's directly from the project directory, but not via Homestead (I'm on the Mac).

The issue is back :-(

Any update please? Today installed fresh version and the issue is still there :(

Mix v0.11.4
For me mix does delete the old versions when using watch. But the issue does happen when using the production flag.

For me regardless if I run watch, dev or production - it does not remove previous versions.
My webpack.mix.js is very simple:

let mix = require('laravel-mix');

mix
    .setPublicPath('public')
    .js('resources/js/front/app.js', 'public/assets/js/front/')
    .sass('resources/scss/front/app.scss', 'public/assets/css/front/')
    .sass('resources/scss/front/wysiwyg.scss', 'public/assets/css/admin/')
    .sass('resources/scss/admin/app.scss', 'public/assets/css/admin/')
    .js('resources/js/admin/app.js', 'public/assets/js/admin/')
    .autoload({
        jquery: ['$', 'window.jQuery']
    })
    .sourceMaps()
    .version();

Having this issue too. I'm using Spark which was using 0.5 of mix, which didn't have this issue. 0.5 wasn't versioning files that were using combine(), so I upgraded to 0.12 yesterday and am now ending up with unremoved versioned files like everyone else.

This is using laravel 5.4/Mix 0.12/Spark 4.09 and homestead on a mac (executing npm from the vm)

Any news?

Same issue here:
Laravel 5.4 / Mix 0.12.1 / Homestead 5.3.2. Same issue doesn't matter if i run npm from my Ubuntu 16.04 host machine or inside the VM.

I confirm the issue. Infinitely annoying. I get it when watching, when running dev or prod. It will just make a new js and css file regardless. Also the other issue where the build takes forever is biting me too.

This is my mix file:

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

It's all pretty basic stuff, just had to add mix.options({processCssUrls: false}); so the build doesn't take over a minute. But yeah, having to manually delete the files is a letdown.

Using:
Mix 0.12.1
Node.js 6.10.0
NPM 3.10.10

same issue here too

```
"laravel-mix": "0.*",
"node": "7.0",
"npm": "5.2",

Any answer?

@mrtdeh Wait for v1.0.0 to be official. That should fix this problem.

Or if you cannot wait, you can be part of the test for v1.0.0 by installing its beta npm install laravel-mix@beta. For more information, see #860

As @ruchern mentioned in this issue.
At the moment I am using laravel-mix version <0.11.4>, It's working great for me!

I can confirm this error as well with this version in package.json "laravel-mix": "0.*",

Please bump to Mix 1.0, which fixes this issue.

laravel-mix version <0.11.4> does not work for me with 'npm run watch'

@ watch /var/www/laravel
node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

@SpaceNet

laravel-mix version <0.11.4> does not work for me with 'npm run watch'

@JeffreyWay

Please bump to Mix 1.0, which fixes this issue.

Laravel-Mix 1.0+ will fix this problem as it will not append hashes to your file name.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rlewkowicz picture rlewkowicz  路  3Comments

dtheb picture dtheb  路  3Comments

Cheddam picture Cheddam  路  3Comments

hasnatbabur picture hasnatbabur  路  3Comments

sdebacker picture sdebacker  路  3Comments