2024-11-07 14:13:39 +02:00
|
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
|
|
2024-12-05 13:20:25 +02:00
|
|
|
import { defineConfig, loadEnv } from 'vite'
|
2024-11-07 14:13:39 +02:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import vueDevTools from 'vite-plugin-vue-devtools'
|
2024-11-14 15:26:44 +02:00
|
|
|
import Components from 'unplugin-vue-components/vite'
|
|
|
|
|
import { PrimeVueResolver } from '@primevue/auto-import-resolver'
|
2024-12-05 13:20:25 +02:00
|
|
|
import Info from 'unplugin-info/vite'
|
2024-12-02 08:50:25 +02:00
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
|
|
|
import { unheadComposablesImports } from 'unhead'
|
2024-12-05 13:20:25 +02:00
|
|
|
import mockData, { type RouteConfig } from 'vite-plugin-mock-data'
|
|
|
|
|
import manifestJSON from 'rollup-plugin-manifest-json'
|
|
|
|
|
import { type ManifestOptions } from 'rollup-plugin-manifest-json/lib/types'
|
2024-11-07 14:13:39 +02:00
|
|
|
|
|
|
|
|
// https://vite.dev/config/
|
2024-12-02 16:08:02 +02:00
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
|
|
console.log('Building in mode', mode)
|
2024-12-05 13:20:25 +02:00
|
|
|
|
|
|
|
|
process.env = { ...loadEnv(mode, process.cwd()), ...process.env }
|
|
|
|
|
|
|
|
|
|
const manifest: ManifestOptions & { id?: string } = Object.fromEntries(
|
|
|
|
|
Object.entries({
|
|
|
|
|
name: process.env.VITE_MANIFEST_NAME,
|
|
|
|
|
short_name: process.env.VITE_MANIFEST_SHORT_NAME,
|
|
|
|
|
id: process.env.VITE_MANIFEST_ID,
|
|
|
|
|
start_url: process.env.VITE_MANIFEST_START_URL,
|
|
|
|
|
scope: process.env.VITE_MANIFEST_SCOPE,
|
|
|
|
|
}).filter((entry) => entry[1] !== undefined),
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-02 16:08:02 +02:00
|
|
|
return {
|
|
|
|
|
build: {
|
|
|
|
|
sourcemap: mode === 'development',
|
2024-12-02 16:50:47 +02:00
|
|
|
reportCompressedSize: false,
|
2024-12-02 18:16:33 +02:00
|
|
|
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
manualChunks(id) {
|
|
|
|
|
if (id.includes('node_modules')) {
|
|
|
|
|
// PouchDB и его плагины
|
|
|
|
|
if (id.includes('pouchdb')) {
|
|
|
|
|
return 'vendor_pouchdb'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QR-коды и библиотеки для работы с ними
|
|
|
|
|
if (id.includes('qr-code-styling')) {
|
|
|
|
|
return 'vendor_qr-code-styling'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PrimeVue и связанные модули
|
|
|
|
|
if (id.includes('primevue')) {
|
|
|
|
|
return 'vendor_primevue'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SVGO и зависимости
|
|
|
|
|
if (id.includes('svgo') || id.includes('@trysound')) {
|
|
|
|
|
return 'vendor_svgo'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Танстэк Vue Query и ядро
|
|
|
|
|
if (id.includes('@tanstack')) {
|
|
|
|
|
return 'vendor_tanstack-query'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Vue и связанные библиотеки
|
|
|
|
|
if (id.includes('vue')) {
|
|
|
|
|
return 'vendor_vue'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id.includes('css-tree')) {
|
|
|
|
|
return 'vendor_css-tree'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id.includes('css-what')) {
|
|
|
|
|
return 'vendor_css-what'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id.includes('domutils')) {
|
|
|
|
|
return 'vendor_domutils'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id.includes('source-map-js')) {
|
|
|
|
|
return 'vendor_source-map-js'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id.includes('csso')) {
|
|
|
|
|
return 'vendor_csso'
|
|
|
|
|
}
|
|
|
|
|
if (id.includes('entities')) {
|
|
|
|
|
return 'vendor_entities'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Остальные модули из node_modules в vendor
|
|
|
|
|
return 'vendor'
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-02 18:28:14 +02:00
|
|
|
if (id.includes('src/api/')) {
|
|
|
|
|
return 'api'
|
|
|
|
|
}
|
|
|
|
|
if (id.includes('src/utils/')) {
|
|
|
|
|
return 'utils'
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-02 18:16:33 +02:00
|
|
|
// По умолчанию ничего не делим
|
|
|
|
|
return null
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-11-07 14:13:39 +02:00
|
|
|
},
|
2024-12-02 16:08:02 +02:00
|
|
|
plugins: [
|
|
|
|
|
vue(),
|
2024-12-05 13:20:25 +02:00
|
|
|
|
|
|
|
|
Info(),
|
|
|
|
|
|
2024-12-02 16:08:02 +02:00
|
|
|
AutoImport({
|
|
|
|
|
imports: ['vue', 'vue-router', unheadComposablesImports[0]],
|
|
|
|
|
}),
|
2024-12-05 13:20:25 +02:00
|
|
|
|
2024-12-02 16:08:02 +02:00
|
|
|
Components({
|
|
|
|
|
resolvers: [PrimeVueResolver()],
|
|
|
|
|
}),
|
2024-12-05 13:20:25 +02:00
|
|
|
|
2024-12-02 16:08:02 +02:00
|
|
|
vueDevTools(),
|
2024-12-05 13:20:25 +02:00
|
|
|
|
|
|
|
|
mockData({
|
|
|
|
|
mockRoutes: {
|
|
|
|
|
'/manifest.json': {
|
|
|
|
|
async handler(req, res) {
|
|
|
|
|
const { default: manifestJSON } = await import('./src/manifest.json')
|
2024-12-05 14:11:11 +02:00
|
|
|
const result = { ...manifestJSON, ...manifest, id: `//${req.headers.host}` }
|
2024-12-05 13:20:25 +02:00
|
|
|
res.statusCode = 200
|
2024-12-05 14:11:11 +02:00
|
|
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
|
|
|
|
res.end(JSON.stringify(result, null, 2))
|
2024-12-05 13:20:25 +02:00
|
|
|
},
|
|
|
|
|
} satisfies RouteConfig,
|
2024-12-05 21:06:57 +02:00
|
|
|
'POST /debug': {
|
|
|
|
|
async handler(req, res) {
|
|
|
|
|
process.stdout.write('\ndebug: ')
|
|
|
|
|
req.pipe(process.stdout)
|
|
|
|
|
res.statusCode = 200
|
|
|
|
|
res.setHeader('Content-Type', 'application/json')
|
|
|
|
|
res.end('true')
|
|
|
|
|
},
|
|
|
|
|
} satisfies RouteConfig,
|
2024-12-05 13:20:25 +02:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
...manifestJSON({
|
|
|
|
|
input: 'src/manifest.json', // Required
|
|
|
|
|
output: './manifest.json',
|
|
|
|
|
minify: mode === 'production',
|
|
|
|
|
manifest,
|
|
|
|
|
}),
|
|
|
|
|
apply: 'build',
|
|
|
|
|
},
|
2024-12-02 16:08:02 +02:00
|
|
|
],
|
|
|
|
|
define: {
|
|
|
|
|
global: 'window', // it is needed for PouchDB
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2024-11-07 14:13:39 +02:00
|
|
|
})
|