Skip to content

Instantly share code, notes, and snippets.

@pdaug
Created December 11, 2024 13:57
Show Gist options
  • Save pdaug/e8ae6077da027e609c6de40ec6c2e3c4 to your computer and use it in GitHub Desktop.
Save pdaug/e8ae6077da027e609c6de40ec6c2e3c4 to your computer and use it in GitHub Desktop.
import { defineConfig } from 'vite';
import { resolve } from 'path';
import fs from 'fs';
// Função para gerar o manifest.json dinâmico
function generateManifest(subdomain) {
const baseManifest = {
name: 'My App',
short_name: 'App',
start_url: '/',
display: 'standalone',
background_color: '#ffffff',
theme_color: '#000000',
};
// Customização baseada no subdomínio
if (subdomain === 'sub1') {
return {
...baseManifest,
name: 'My App - Subdomain 1',
theme_color: '#ff0000',
};
} else if (subdomain === 'sub2') {
return {
...baseManifest,
name: 'My App - Subdomain 2',
theme_color: '#00ff00',
};
}
return baseManifest;
}
// Exportação da configuração do Vite
export default defineConfig(({ mode }) => {
// Subdomínio vindo de variáveis de ambiente ou argumentos de linha de comando
const subdomain = process.env.SUBDOMAIN || 'default';
// Gerar manifest dinamicamente
const manifest = generateManifest(subdomain);
// Escrever o arquivo de manifest no disco
fs.writeFileSync(
resolve(__dirname, 'dist', 'manifest.json'),
JSON.stringify(manifest, null, 2)
);
return {
build: {
outDir: 'dist',
},
server: {
host: true,
},
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment