revite/vite.config.ts

104 lines
2.7 KiB
TypeScript
Raw Normal View History

2021-06-18 10:35:35 -04:00
import { resolve } from 'path'
2021-06-22 08:47:47 -04:00
import { readFileSync } from 'fs'
2021-06-18 07:05:01 -04:00
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'
2021-06-18 14:25:33 -04:00
import { VitePWA } from 'vite-plugin-pwa'
2021-06-22 08:47:47 -04:00
import replace from '@rollup/plugin-replace'
function getGitRevision() {
try {
const rev = readFileSync('.git/HEAD').toString().trim();
if (rev.indexOf(':') === -1) {
return rev;
} else {
return readFileSync('.git/' + rev.substring(5)).toString().trim();
}
} catch (err) {
console.error('Failed to get Git revision.');
return '?';
}
}
2021-06-18 07:05:01 -04:00
2021-06-22 14:45:44 -04:00
function getGitBranch() {
try {
const rev = readFileSync('.git/HEAD').toString().trim();
if (rev.indexOf(':') === -1) {
return 'DETACHED';
} else {
return rev.split('/').pop();
}
} catch (err) {
console.error('Failed to get Git branch.');
return '?';
}
}
function getVersion() {
return readFileSync('VERSION').toString();
}
2021-06-22 14:59:02 -04:00
const branch = getGitBranch();
const isNightly = false;//branch !== 'production';
2021-06-22 14:59:02 -04:00
const iconPrefix = isNightly ? 'nightly-' : '';
2021-06-18 07:05:01 -04:00
export default defineConfig({
2021-06-18 14:25:33 -04:00
plugins: [
preact(),
VitePWA({
2021-06-22 09:22:35 -04:00
srcDir: 'src',
filename: 'sw.ts',
strategies: 'injectManifest',
2021-06-18 14:25:33 -04:00
manifest: {
2021-07-07 18:01:27 -04:00
name: isNightly ? "Revolt Nightly" : "Revolt",
short_name: "Revolt",
description: isNightly ? "Early preview builds of Revolt." : "User-first, privacy-focused chat platform.",
2021-06-18 14:25:33 -04:00
categories: ["messaging"],
start_url: "/",
2021-07-07 18:30:30 -04:00
orientation: "any",
2021-06-18 14:25:33 -04:00
display: "standalone",
background_color: "#101823",
2021-07-07 19:28:59 -04:00
theme_color: "#101823",
2021-06-18 14:25:33 -04:00
icons: [
{
2021-06-22 14:59:02 -04:00
"src": `/assets/icons/${iconPrefix}android-chrome-192x192.png`,
2021-06-18 14:25:33 -04:00
"type": "image/png",
"sizes": "192x192"
},
{
2021-06-22 14:59:02 -04:00
"src": `/assets/icons/${iconPrefix}android-chrome-512x512.png`,
2021-06-18 14:25:33 -04:00
"type": "image/png",
"sizes": "512x512"
2021-07-07 18:30:30 -04:00
},
{
"src": `/assets/icons/monochrome.svg`,
2021-07-08 06:56:07 -04:00
"type": "image/svg+xml",
"sizes": "48x48 72x72 96x96 128x128 256x256",
2021-07-07 18:47:53 -04:00
"purpose": "monochrome"
2021-07-07 18:30:30 -04:00
},
{
"src": `/assets/icons/masking-512x512.png`,
"type": "image/png",
"sizes": "512x512",
"purpose": "maskable"
2021-06-18 14:25:33 -04:00
}
]
2021-06-22 09:22:35 -04:00
}
2021-06-22 08:47:47 -04:00
}),
replace({
__GIT_REVISION__: getGitRevision(),
2021-06-22 14:45:44 -04:00
__GIT_BRANCH__: getGitBranch(),
__APP_VERSION__: getVersion(),
2021-06-22 08:47:47 -04:00
preventAssignment: true
2021-06-18 14:25:33 -04:00
})
],
2021-06-18 10:35:35 -04:00
build: {
2021-06-19 07:34:53 -04:00
sourcemap: true,
2021-06-18 10:35:35 -04:00
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
ui: resolve(__dirname, 'ui/index.html')
}
}
}
2021-06-18 07:05:01 -04:00
})