Files
it-tools/vite.config.ts
T
SebastianandClaude Fable 5 239c69ee40 feat: mobile UX overhaul, theme flash prevention and build cleanup (#474)
* feat: mobile UX overhaul, theme flash prevention and build cleanup

UI/UX (mostly mobile):
- Prevent white flash on load: pre-paint inline style + script in
  index.html applies the persisted theme before first paint.
- Match browser chrome to the app background: theme-color meta kept in
  sync for Android/older iOS, and body background pinned to the Layout
  color for Safari 26+, which ignores theme-color and samples the page.
- Make the document the app's scroller instead of n-layout's nested
  container: single scrollbar, native iOS tap-status-bar-to-scroll-top,
  natural toolbar collapsing; desktop sider becomes sticky and router
  scrollBehavior restores/resets scroll on navigation.
- Full-width mobile menu that fades in under an always-visible sticky
  top bar, seamless app background without the hero gradient, closes on
  navigation (including About while already on /about), scroll-locked
  behind, symmetric spacing around the title block and icon row.
- Language selector and theme toggle become icon dropdowns; theme
  supports System/Light/Dark via useColorMode (same storage as before).
- Route-change loading spinner scoped to the page area so the nav bar
  stays visible; spinner remains cosmetic-only (350ms delay).
- Halve content padding on small screens; reduce home top padding.
- Full-width expand/collapse tools button so its width doesn't jump.
- No sticky hover styles on touch devices (hover gated behind
  @media (hover: hover)).

Build:
- Rename deprecated rolldown output.advancedChunks to codeSplitting.
- Fix unocss 'unmatched utility' warnings in the pretty-scrollbar
  shortcut; override js-sha256 to 0.11.x (drops eval); bump
  javascript-obfuscator to 5.4.6.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TNayL5ianBBucVapfkM8CC

* Remove unnecessary comment

* Refresh lockfile, remove releaseage ignore

Signed-off-by: Sebastian Danielsson <sebastian.danielsson@proton.me>

* chore: remove unused LocaleSelector component

Language selection moved into the NavbarButtons dropdown; nothing
references this component anymore. Its i18n keys are left in place.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TNayL5ianBBucVapfkM8CC

---------

Signed-off-by: Sebastian Danielsson <sebastian.danielsson@proton.me>
Co-authored-by: Claude <noreply@anthropic.com>
2026-07-11 23:21:34 +02:00

210 lines
7.3 KiB
TypeScript

import { URL, fileURLToPath } from 'node:url';
import { resolve } from 'node:path';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import wasm from 'vite-plugin-wasm';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import markdown from 'unplugin-vue-markdown/vite';
import svgLoader from 'vite-svg-loader';
import { VitePWA } from 'vite-plugin-pwa';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import Unocss from 'unocss/vite';
import { configDefaults } from 'vitest/config';
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
import { visualizer } from 'rollup-plugin-visualizer';
const baseUrl = process.env.BASE_URL || '/';
// Locales are code-split: only en is bundled eagerly, the rest become lazy chunks fetched on
// first use (see src/plugins/i18n.plugin.ts). VITE_AVAILABLE_LOCALES filters the locales
// offered at runtime instead of trimming the build.
const includeLocales = [
resolve(__dirname, 'src/tools/*/locales/**'),
resolve(__dirname, 'locales/**'),
];
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
VueI18n({
runtimeOnly: true,
compositionOnly: true,
fullInstall: true,
include: includeLocales,
strictMessage: false,
escapeHtml: true,
}),
AutoImport({
imports: [
'vue',
'vue-router',
'@vueuse/core',
'vue-i18n',
{
'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar'],
},
],
vueTemplate: true,
}),
Icons({ compiler: 'vue3' }),
vue({
include: [/\.vue$/, /\.md$/],
}),
vueJsx(),
markdown(),
svgLoader(),
VitePWA({
registerType: 'autoUpdate',
workbox: {
// Precache only the app shell so the service worker doesn't download every
// tool chunk and WASM binary (~160 MB) on first visit; hashed assets are
// cached on demand as tools are opened. Set VITE_PWA_FULL_PRECACHE=true to
// restore full offline precaching of everything.
globPatterns: (process.env.VITE_PWA_FULL_PRECACHE === 'true' && !process.env.VITE_VERCEL_DEPLOY)
? ['**\/*.{js,wasm,css,html}']
: ['**\/*.{css,html}'],
maximumFileSizeToCacheInBytes: 25 * 1024 ** 2,
navigateFallback: `${baseUrl}index.html`,
runtimeCaching: [
{
urlPattern: ({ sameOrigin, request }) => sameOrigin
&& (request.destination === 'script' || request.destination === 'worker'),
handler: 'CacheFirst',
options: {
cacheName: 'app-chunks',
expiration: { maxEntries: 2000, maxAgeSeconds: 60 * 60 * 24 * 30 },
cacheableResponse: { statuses: [0, 200] },
},
},
{
urlPattern: ({ sameOrigin, url }) => sameOrigin && url.pathname.endsWith('.wasm'),
handler: 'CacheFirst',
options: {
cacheName: 'app-wasm',
expiration: { maxEntries: 30, maxAgeSeconds: 60 * 60 * 24 * 30 },
cacheableResponse: { statuses: [0, 200] },
},
},
],
},
strategies: 'generateSW',
manifest: {
name: 'IT Tools',
description: 'Aggregated set of useful tools for developers.',
display: 'standalone',
start_url: `${baseUrl}?utm_source=pwa&utm_medium=pwa`,
scope: baseUrl,
orientation: 'any',
theme_color: '#18a058',
background_color: '#f1f5f9',
icons: [
{
src: `${baseUrl}favicon-16x16.png`,
type: 'image/png',
sizes: '16x16',
},
{
src: `${baseUrl}favicon-32x32.png`,
type: 'image/png',
sizes: '32x32',
},
{
src: `${baseUrl}android-chrome-192x192.png`,
sizes: '192x192',
type: 'image/png',
},
{
src: `${baseUrl}android-chrome-512x512.png`,
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
},
}),
Components({
dirs: ['src/'],
extensions: ['vue', 'md'],
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
// dtsTsx generates invalid `const 'Name.demo':` declarations for
// components whose file names contain dots
dtsTsx: false,
}),
Unocss(),
nodePolyfills(),
wasm(),
visualizer(),
],
base: baseUrl,
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'node:fs/promises': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'node:fs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'fs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'@babel/core': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'isolated-vm': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'onnxruntime-node': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'unpdf/pdfjs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'webcrypto-liner-shim': !process.env.VERCEL ? 'webcrypto-liner-shim' : fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
},
},
define: {
'import.meta.env.PACKAGE_VERSION': JSON.stringify(process.env.npm_package_version),
},
test: {
exclude: [...configDefaults.exclude, '**/*.e2e.spec.ts'],
server: {
deps: {
inline: ['otpauth-migration', 'proto'],
},
},
},
build: {
target: 'esnext',
// sourcemap: !process.env.VERCEL,
// minify: !process.env.VERCEL,
reportCompressedSize: !process.env.VERCEL,
// cssMinify: false,
// modulePreload: false,
rolldownOptions: {
external: ['regex', './out/isolated_vm', 'isolated-vm', 'onnxruntime-node', 'unpdf/pdfjs'],
output: {
format: 'es',
codeSplitting: {
// Tool icons are loaded through per-icon dynamic imports (see src/tools/*/index.ts);
// merge them into a single lazy chunk instead of ~450 tiny ones.
// includeDependenciesRecursively must stay off: with it, shared helper modules
// get captured into this chunk and entry chunks end up statically importing it,
// which drags the whole icon set back into the startup payload.
groups: [
{
name: 'tool-icons',
test: /node_modules[\\/](?:@vicons[\\/]|@tabler[\\/]icons-vue[\\/]dist[\\/]esm[\\/]icons[\\/])/,
includeDependenciesRecursively: false,
},
],
},
},
},
},
optimizeDeps: {
include: ['isolated-vm', '@lezer/highlight', 'pdfjs-dist', 'onnxruntime-node', 'onnxruntime-web', 'unpdf', 'unpdf/pdfjs', ...(process.env.VERCEL ? ['webcrypto-liner-shim'] : [])], // optionally specify dependency name
},
// server: {
// headers: {
// 'Cross-Origin-Resource-Policy': 'same-site',
// 'Cross-Origin-Opener-Policy': 'same-origin',
// 'Cross-Origin-Embedder-Policy': 'require-corp',
// },
// },
});