It looks like now the old files are overwritten, anyway I'm still experiencing an issue with the mix-manifest.json
file not deleting files that are removed, so in case someone else encounters a similar problem, here is how I solved it.
Through the webpackConfig
method I'm using the splitChunksPlugin
from webpack, which reduces duplication between chunks by creating additional chunks when there is enough code in common between modules.
This means that in some cases the total number of dynamically added chunks is different between the dev and the prod environment, because in development files are larger, so it's easier to share more code between the files.
So the fact that the mix-manifest file is not updating when the build removes files is causing some issues (especially when working with other people) and I'd like to share how I solved the issue.
1. Laravel-Mix-Clean
In order to avoid having more files than needed, I'm deleting all the files at each build. I had to change the folder structure and pass the correct path to the method, but this didn't cause many issues.
npm install laravel-mix-clean --save-dev
and in the mix file
require('laravel-mix-clean');
// [...]
.clean({
cleanOnceBeforeBuildPatterns: ['./js/*'],
});
2. Removing the manifest
Having the files in sync was not enough, so I had to remove the manifest file at each new build. In my set-up I have three concurrent builds (each with its own webpack.mix
file), so I don't know which one will finish first.
The solution was to install the del-cli
package (which is used internally by the clean-webpack-plugin
, which in turn is used by laravel-mix-clean
) and to delete the manifest file before each build.
npm install del-cli --save-dev
package.json
"scripts": {
"clear-manifest": "del-cli public/mix-manifest.json",
// [...]
"development": "npm run clear-manifest && concurrently \"npm run css-dev\" \"npm run js-dev\" \"npm run js-dev-modern\"",
}
I hope this helps other people with similar issues.