Curious why you are making your own hash? Be aware that vite ignores image files with the same content. This might be "fixed" in the next version
Oct 13, 2022
14
Level 1
Vite not copying all static assets
Hi, I've switched to Vite in my current laravel project. I am adding my static assets with the following code:
import.meta.glob([
'../../media/**/*'
]);
In my Vite config I have the following setting:
build: {
rollupOptions: {
output: {
assetFileNames(assetInfo) {
const pathToFile = normalizePath(assetInfo.name);
// Check if the file is in the resources/assets/media folder
if (pathToFile.includes('resources/assets/media')) {
// Get path to the file relative to the resources/assets/media folder
const pathToMediaFile = pathToFile.split('resources/assets/media/')[1];
// Remove filename and extension
const pathToFileWithoutMediaAndFilename = pathToMediaFile.substring(0, pathToMediaFile.lastIndexOf("/"));
// Return the path to the media folder
return `assets/media/${pathToFileWithoutMediaAndFilename}/[name]-[hash].[ext]`;
}
return 'assets/[name]-[hash][extname]';
},
},
},
},
Most of the files are copied correctly but some are missing. I've already debugged the function "assetFileNames" and the files which are missing are processed and the right path is set. Altough they won't be copied to the folder.
Any ideas?
Level 102
@Basti0208 Exactly. You can use the beta release if you cannot wait for an official release. https://github.com/vitejs/vite/blob/v3.2.0-beta.2/packages/vite/CHANGELOG.md#320-beta0-2022-10-05
Please or to participate in this conversation.