'Vite - empty assets folder (not whole outputDir)
Due to other construction services e.g. from the CMS that is in use also puts files in the same folder as outPutDir
I only need to empty the assets folder. At the same time, I want to keep the folder structure that comes by default by only specifying outPutDir
Is this possible with Vite?
I do not find anything about this in the documentation for Vite. However, this does not mean that it is not mentioned somewhere.
build: {
outDir: '../wwwroot/',
emptyOutDir: true,
rollupOptions: {
output: {
chunkFileNames: 'assets/js/[name].[hash].js',
entryFileNames: 'assets/js/[name].[hash].js',
assetFileNames: ({name}) => {
if (/\.(gif|jpe?g|png|svg)$/.test(name ?? '')) {
return 'assets/images/[name].[hash][extname]';
}
if (/\.css$/.test(name ?? '')) {
return 'assets/css/[name].[hash][extname]';
}
return 'assets/[name].[hash][extname]';
},
},
},
},
Solution 1:[1]
The solution in my case is to reroute where the CMS pick up the assets files from the frontend build.
It does not solve my original challenge but it solves my problem.
build: {
outDir: '../wwwroot/public/',
sourcemap: true,
manifest: true,
reportCompressedSize: true,
emptyOutDir: true,
rollupOptions: {
output: {
chunkFileNames: 'js/[name].[hash].js',
entryFileNames: 'js/[name].[hash].js',
assetFileNames: ({ name }) => {
if (/\.(gif|jpe?g|png|svg)$/.test(name ?? '')) {
return 'images/[name].[hash][extname]';
}
if (/\.css$/.test(name ?? '')) {
return 'css/[name].[hash][extname]';
}
return '[name].[hash][extname]';
},
},
},
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Helge |