2022-12-10 09:14:48 +00:00
|
|
|
import preact from '@preact/preset-vite';
|
2022-12-15 06:42:34 +00:00
|
|
|
import { execSync } from 'child_process';
|
2022-12-28 05:47:11 +00:00
|
|
|
import fs from 'fs';
|
2022-12-13 12:42:09 +00:00
|
|
|
import { resolve } from 'path';
|
2022-12-22 11:38:02 +00:00
|
|
|
import { defineConfig, loadEnv, splitVendorChunkPlugin } from 'vite';
|
2022-12-28 05:47:11 +00:00
|
|
|
import htmlPlugin from 'vite-plugin-html-config';
|
2022-12-27 12:47:23 +00:00
|
|
|
import VitePluginHtmlEnv from 'vite-plugin-html-env';
|
2022-12-19 06:51:56 +00:00
|
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
|
|
|
2023-01-02 06:22:01 +00:00
|
|
|
const { NODE_ENV } = process.env;
|
|
|
|
const { VITE_CLIENT_NAME: CLIENT_NAME, VITE_APP_ERROR_LOGGING: ERROR_LOGGING } =
|
|
|
|
loadEnv('production', process.cwd());
|
2022-12-10 09:14:48 +00:00
|
|
|
|
2022-12-15 06:42:34 +00:00
|
|
|
const commitHash = execSync('git rev-parse --short HEAD').toString().trim();
|
|
|
|
|
2022-12-28 05:47:11 +00:00
|
|
|
const rollbarCode = fs.readFileSync(
|
|
|
|
resolve(__dirname, './rollbar.js'),
|
|
|
|
'utf-8',
|
|
|
|
);
|
|
|
|
|
2022-12-10 09:14:48 +00:00
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
2022-12-19 06:51:56 +00:00
|
|
|
mode: NODE_ENV,
|
2022-12-15 06:42:34 +00:00
|
|
|
define: {
|
|
|
|
__BUILD_TIME__: JSON.stringify(Date.now()),
|
|
|
|
__COMMIT_HASH__: JSON.stringify(commitHash),
|
|
|
|
},
|
2022-12-19 06:51:56 +00:00
|
|
|
plugins: [
|
|
|
|
preact(),
|
|
|
|
splitVendorChunkPlugin(),
|
2022-12-27 12:47:23 +00:00
|
|
|
VitePluginHtmlEnv(),
|
2022-12-28 05:47:11 +00:00
|
|
|
htmlPlugin({
|
2023-01-02 06:22:01 +00:00
|
|
|
headScripts: ERROR_LOGGING ? [rollbarCode] : [],
|
2022-12-28 05:47:11 +00:00
|
|
|
}),
|
2022-12-19 06:51:56 +00:00
|
|
|
VitePWA({
|
|
|
|
manifest: {
|
|
|
|
name: CLIENT_NAME,
|
|
|
|
short_name: CLIENT_NAME,
|
|
|
|
description: 'Minimalistic opinionated Mastodon web client',
|
|
|
|
theme_color: '#ffffff',
|
|
|
|
icons: [
|
|
|
|
{
|
|
|
|
src: 'logo-192.png',
|
|
|
|
sizes: '192x192',
|
|
|
|
type: 'image/png',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: 'logo-512.png',
|
|
|
|
sizes: '512x512',
|
|
|
|
type: 'image/png',
|
|
|
|
},
|
2022-12-20 11:12:25 +00:00
|
|
|
{
|
|
|
|
src: 'logo-maskable-512.png',
|
|
|
|
sizes: '512x512',
|
|
|
|
type: 'image/png',
|
|
|
|
purpose: 'maskable',
|
|
|
|
},
|
2022-12-19 06:51:56 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
strategies: 'injectManifest',
|
|
|
|
injectRegister: 'inline',
|
|
|
|
injectManifest: {
|
|
|
|
// Prevent "Unable to find a place to inject the manifest" error
|
|
|
|
injectionPoint: undefined,
|
|
|
|
},
|
|
|
|
devOptions: {
|
|
|
|
enabled: NODE_ENV === 'development',
|
|
|
|
type: 'module',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
2022-12-13 12:42:09 +00:00
|
|
|
build: {
|
2022-12-15 03:47:11 +00:00
|
|
|
sourcemap: true,
|
2022-12-13 12:42:09 +00:00
|
|
|
rollupOptions: {
|
|
|
|
input: {
|
|
|
|
main: resolve(__dirname, 'index.html'),
|
|
|
|
compose: resolve(__dirname, 'compose/index.html'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-10 09:14:48 +00:00
|
|
|
});
|