Skip to content

Commit

Permalink
Merge branch 'fix/prevent-hotjar-cache' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuseduardomedeiros committed Sep 5, 2024
2 parents 8e2207d + e8f5280 commit 92d3369
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import { fileURLToPath, URL } from 'node:url';
import { createHash } from 'crypto';
import fs from 'fs';
import path from 'path';

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';

const htmlTransform = () => ({
name: 'html-transform',
apply: 'build',
closeBundle() {
const indexPath = path.resolve(__dirname, 'dist', 'index.html');

const hash = createHash('md5')
.update(Date.now().toString())
.digest('hex')
.substring(0, 8);

let html = fs.readFileSync(indexPath, 'utf-8');

// Added the query string ?v=[hash] for CSS and JS only
html = html.replace(/(\/assets\/insights\.(js|css))/g, `$1?v=${hash}`);

fs.writeFileSync(indexPath, html);
},
});

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), vueJsx()],
plugins: [vue(), vueJsx(), htmlTransform()],
css: {
preprocessorOptions: {
scss: {
Expand All @@ -21,4 +44,19 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
build: {
rollupOptions: {
output: {
// Define o nome dos arquivos sem hash
entryFileNames: 'assets/insights.js',
chunkFileNames: 'assets/insights.js', // Caso tenha chunks, também aplica o nome fixo
assetFileNames: (assetInfo) => {
if (assetInfo.name.endsWith('.css')) {
return 'assets/insights.css'; // Define o nome do arquivo CSS sem hash
}
return 'assets/' + assetInfo.name;
},
},
},
},
});

0 comments on commit 92d3369

Please sign in to comment.