To avoid garbage accumulation in build directory, would be useful to add cleaning of output/build directory before building ?
Example with Webpack and clean-webpack-plugin
馃憤 a method to recursively remove a folder would be a nice usefull addition !
If it can help, i use the following workaround :
const { mix } = require('laravel-mix');
const Clean = require('clean-webpack-plugin');
mix.webpackConfig({
plugins: [
new Clean(['some/destination/path'], {verbose: false})
],
})
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.copy('some/assets/path/*.ext', 'some/destination/path/');
We already clean out any old files, and there isn't a specific build directory.
Can you give me a specific Mix use-case that we need to solve?
I think that @gydammin is talking about some use-case where, for example, your mix build script copy some static assets in public custom sub-directory. At some point, these assets may change, and clean (ie delete) this sub-directory before copy things inside, ensure that no old deprecated 'artifacts' files are left.
A mix.clean() helper method which behave the same way, may be a usefull addition. But anyway, manually using clean-webpack-plugin like in my previous example seems fine 馃槃
The simplest way would be to add one more entry in your package.json scripts section:
"prewatch": "del-cli dist -f",
Naming it prewatchmakes it automatically run before watch.
predev works as well.
It 's always better to clean first than generate
@JeffreyWay : basically, if I am adding new files or removing old ones, or renaming some that are not bundled together, there will be garbage left.
Static files are one case, but if I am changing output from app.js to backoffice.js by example in webpack.mix.js, there will be backoffice.js and app.js will be still present.
Anyway "prewatch": "del-cli dist -f", as well as pre{X,Y,Z} works, but may be a good option to clean output dir anyway first. This is also missing for elixir as well as far I remember
Eps, no, prewach is not a solution as it remove everything and when watching, it recompiles only modified files :)
This is resolved in Mix 1.0+.
Most helpful comment
If it can help, i use the following workaround :