revite/vite.config.ts

106 lines
3 KiB
TypeScript
Raw Normal View History

import replace from "@rollup/plugin-replace";
import { readFileSync } from "fs";
import { resolve } from "path";
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
import preact from "@preact/preset-vite";
2021-06-22 08:47:47 -04:00
function getGitRevision() {
try {
const rev = readFileSync(".git/HEAD").toString().trim();
if (rev.indexOf(":") === -1) {
return rev;
}
return readFileSync(`.git/${rev.substring(5)}`)
.toString()
.trim();
} catch (err) {
console.error("Failed to get Git revision.");
return "?";
2021-06-22 08:47:47 -04:00
}
}
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";
}
return rev.split("/").pop();
} catch (err) {
console.error("Failed to get Git branch.");
return "?";
2021-06-22 14:45:44 -04:00
}
}
function getVersion() {
return readFileSync("VERSION").toString();
}
2021-06-18 07:05:01 -04:00
export default defineConfig({
plugins: [
preact(),
VitePWA({
srcDir: "src",
filename: "sw.ts",
strategies: "injectManifest",
manifest: {
name: "Revolt",
short_name: "Revolt",
description: "User-first, privacy-focused chat platform.",
categories: ["messaging"],
start_url: "/",
orientation: "portrait",
display: "standalone",
background_color: "#101823",
theme_color: "#101823",
icons: [
{
src: `/assets/icons/android-chrome-192x192.png`,
type: "image/png",
sizes: "192x192",
},
{
src: `/assets/icons/android-chrome-512x512.png`,
type: "image/png",
sizes: "512x512",
},
{
src: `/assets/icons/monochrome.svg`,
type: "image/svg+xml",
sizes: "48x48 72x72 96x96 128x128 256x256",
purpose: "monochrome",
},
{
src: `/assets/icons/masking-512x512.png`,
type: "image/png",
sizes: "512x512",
purpose: "maskable",
},
],
2021-07-07 18:30:30 -04:00
},
}),
replace({
__GIT_REVISION__: getGitRevision(),
__GIT_BRANCH__: getGitBranch(),
__APP_VERSION__: getVersion(),
preventAssignment: true,
}),
],
build: {
sourcemap: true,
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
ui: resolve(__dirname, "ui/index.html"),
2021-07-07 18:30:30 -04:00
},
},
},
optimizeDeps: {
exclude: ["revolt.js"],
},
});