- Added `wdio.conf.js` for configuring WebdriverIO. - Introduced `test/specs/sample.spec.js` for initial test case setup to validate home page loading. - Updated `vite.config.js` to include SCSS preprocessor configuration for improving CSS handling. - Added required dependencies for WebdriverIO and related services in `package-lock.json`.
149 lines
6.3 KiB
JavaScript
149 lines
6.3 KiB
JavaScript
import { fileURLToPath, URL } from 'node:url'
|
|
import { defineConfig } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import vueDevTools from 'vite-plugin-vue-devtools'
|
|
import { viteSingleFile } from 'vite-plugin-singlefile'
|
|
import { VitePWA } from 'vite-plugin-pwa'
|
|
import VueJsx from '@vitejs/plugin-vue-jsx'
|
|
import { execSync } from 'node:child_process'
|
|
|
|
function getGitCommit() {
|
|
try {
|
|
return execSync('git rev-parse --short HEAD').toString().trim()
|
|
} catch {
|
|
return 'unknown'
|
|
}
|
|
}
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const isProd = mode === 'production'
|
|
|
|
// Set COMMIT_HASH env var for use in the app
|
|
const version = process.env.npm_package_version || '0.0.0'
|
|
const commit = getGitCommit()
|
|
console.log(`Building version ${version} (commit: ${commit})`)
|
|
process.env.COMMIT_HASH = commit
|
|
process.env.APP_VERSION = version
|
|
|
|
// Keep relative base for static hosting; align manifest with base
|
|
const base = '/'
|
|
const pwaScope = base === './' ? '.' : base
|
|
|
|
// Enable single-file build only when explicitly requested (disabled by default for PWA)
|
|
const enableSingleFile = process.env.VITE_SINGLE_FILE === 'true' && !isProd
|
|
|
|
return {
|
|
base,
|
|
plugins: [
|
|
vue(),
|
|
VueJsx(),
|
|
!isProd && vueDevTools(),
|
|
enableSingleFile && viteSingleFile(),
|
|
VitePWA({
|
|
registerType: 'autoUpdate',
|
|
devOptions: {
|
|
enabled: true // keep for local dev
|
|
},
|
|
workbox: {
|
|
maximumFileSizeToCacheInBytes: 12 * 1024 * 1024,
|
|
cleanupOutdatedCaches: true,
|
|
skipWaiting: true,
|
|
clientsClaim: true,
|
|
globPatterns: ['**/*.{js,css,html,ico,svg,woff2}'],
|
|
globIgnores: ['**/registerSW.js', '**/sw.js'],
|
|
runtimeCaching: [
|
|
{
|
|
// cache API responses
|
|
urlPattern: ({ url }) => url.origin === 'https://api.truckwash.dk',
|
|
handler: 'NetworkFirst',
|
|
options: {
|
|
cacheName: 'pleno-api-cache',
|
|
expiration: {
|
|
maxEntries: 100,
|
|
maxAgeSeconds: 5 * 60 // 5 minutes
|
|
},
|
|
networkTimeoutSeconds: 10,
|
|
cacheableResponse: {
|
|
statuses: [200] // avoid opaque caching for API
|
|
}
|
|
}
|
|
},
|
|
{
|
|
// cache same-origin static assets
|
|
urlPattern: ({ sameOrigin, request }) =>
|
|
sameOrigin && ['style', 'script', 'font'].includes(request.destination),
|
|
handler: 'StaleWhileRevalidate',
|
|
options: {
|
|
cacheName: 'pleno-website-cache',
|
|
expiration: {
|
|
maxEntries: 50,
|
|
maxAgeSeconds: 24 * 60 * 60 // 24 hours
|
|
},
|
|
cacheableResponse: {
|
|
statuses: [0, 200]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
// cache images (restrict to same-origin; loosen if you use a trusted CDN)
|
|
urlPattern: ({ sameOrigin, request }) =>
|
|
sameOrigin && request.destination === 'image',
|
|
handler: 'CacheFirst',
|
|
options: {
|
|
cacheName: 'pleno-image-cache',
|
|
expiration: {
|
|
maxEntries: 100,
|
|
maxAgeSeconds: 7 * 24 * 60 * 60 // 7 days
|
|
},
|
|
cacheableResponse: {
|
|
statuses: [0, 200]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
manifest: {
|
|
name: 'Pleno',
|
|
short_name: 'Pleno',
|
|
description: 'Access your Pleno accounts and transactions from anywhere.',
|
|
theme_color: '#063651',
|
|
background_color: '#0787bb',
|
|
// Use relative scope when base is relative
|
|
start_url: pwaScope,
|
|
scope: pwaScope,
|
|
display: 'standalone',
|
|
orientation: 'portrait',
|
|
launch_handler: { client_mode: 'navigate-existing' },
|
|
icons: [
|
|
{ src: 'icons/icon-192x192.png', sizes: '192x192', type: 'image/png' },
|
|
{ src: 'icons/icon-512x512.png', sizes: '512x512', type: 'image/png' },
|
|
// Optional: add a maskable icon
|
|
// { src: 'icons/icon-512x512-maskable.png', sizes: '512x512', type: 'image/png', purpose: 'any maskable' }
|
|
],
|
|
id: 'pleno-pwa-test'
|
|
}
|
|
})
|
|
].filter(Boolean),
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
}
|
|
},
|
|
define: {
|
|
'import.meta.env.VITE_BUILD_DATE': JSON.stringify(new Date().toISOString()),
|
|
'import.meta.env.VITE_APP_VERSION': JSON.stringify(process.env.APP_VERSION || '0.0.0'),
|
|
'import.meta.env.VITE_COMMIT_HASH': JSON.stringify(process.env.COMMIT_HASH || 'dev'),
|
|
// Tip: import.meta.env.DEV/PROD are available at runtime
|
|
'import.meta.env.VITE_IS_DEV': JSON.stringify(!isProd)
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
api: 'modern-compiler',
|
|
silenceDeprecations: ['import', 'global-builtin', 'legacy-js-api']
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|