Skip to content

Commit

Permalink
random name for changable assets
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Feb 27, 2024
1 parent 204e0d3 commit 8a2407f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
// Utilities
import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'node:url'
import { randomBytes } from 'crypto';

function getUniqueFileName(template) {
if (template.includes('.js') || template.includes('.css')) {
const hash = randomBytes(8).toString('hex');
return template.replace('[name]', hash);
}
return template;
}

export default defineConfig({
base: '',
Expand All @@ -26,8 +35,12 @@ export default defineConfig({
rollupOptions: {
output: {
inlineDynamicImports: true,
entryFileNames: 'assets/[name].js',
assetFileNames: 'assets/[name].[ext]',
entryFileNames: getUniqueFileName('assets/[name].js'),
chunkFileNames: getUniqueFileName('assets/[name].js'),
assetFileNames: (assetInfo) => {
if (assetInfo.name == "index.css") return getUniqueFileName('assets/[name].css');
return 'assets/' + assetInfo.name;
},
},
}
},
Expand Down

0 comments on commit 8a2407f

Please sign in to comment.