phanpy/vite.config.js

98 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-12-10 12:14:48 +03:00
import preact from '@preact/preset-vite';
import { execSync } from 'child_process';
import fs from 'fs';
import { resolve } from 'path';
import { defineConfig, loadEnv, splitVendorChunkPlugin } from 'vite';
2023-02-28 10:27:42 +03:00
import generateFile from 'vite-plugin-generate-file';
import htmlPlugin from 'vite-plugin-html-config';
import VitePluginHtmlEnv from 'vite-plugin-html-env';
import { VitePWA } from 'vite-plugin-pwa';
2023-01-02 10:09:31 +03:00
import removeConsole from 'vite-plugin-remove-console';
2023-01-02 09:22:01 +03: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 12:14:48 +03:00
2023-02-28 10:27:42 +03:00
const now = new Date();
const commitHash = execSync('git rev-parse --short HEAD').toString().trim();
const rollbarCode = fs.readFileSync(
resolve(__dirname, './rollbar.js'),
'utf-8',
);
2022-12-10 12:14:48 +03:00
// https://vitejs.dev/config/
export default defineConfig({
mode: NODE_ENV,
define: {
2023-02-28 10:27:42 +03:00
__BUILD_TIME__: JSON.stringify(now),
__COMMIT_HASH__: JSON.stringify(commitHash),
},
plugins: [
preact(),
splitVendorChunkPlugin(),
VitePluginHtmlEnv(),
removeConsole({
includes: ['log', 'debug', 'info', 'warn', 'error'],
}),
htmlPlugin({
2023-01-02 09:22:01 +03:00
headScripts: ERROR_LOGGING ? [rollbarCode] : [],
}),
2023-02-28 10:27:42 +03:00
generateFile([
{
type: 'json',
output: './version.json',
data: {
buildTime: now,
commitHash,
},
},
]),
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 14:12:25 +03:00
{
src: 'logo-maskable-512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
},
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',
},
}),
],
build: {
sourcemap: true,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
compose: resolve(__dirname, 'compose/index.html'),
},
},
},
2022-12-10 12:14:48 +03:00
});