-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
152 lines (148 loc) · 4.44 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/// <reference types="vitest" />
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import vue from '@vitejs/plugin-vue'
import replace from '@rollup/plugin-replace'
import { visualizer } from 'rollup-plugin-visualizer'
import type { PluginOption } from 'vite'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
import { configDefaults } from 'vitest/config'
import type { ManifestOptions, VitePWAOptions } from 'vite-plugin-pwa'
import { VitePWA } from 'vite-plugin-pwa'
import tailwind from 'tailwindcss'
import tailwindNesting from 'tailwindcss/nesting'
import autoprefixer from 'autoprefixer'
const sw = process.env.SW === 'true'
const claims = process.env.CLAIMS === 'true'
const pwaOptions: Partial<VitePWAOptions> = {
base: '/',
mode: process.env.SW_DEV === 'true' ? 'development' : 'production',
includeAssets: ['*.ico', '*.svg', '*.png'],
selfDestroying: process.env.SW_DESTROY === 'true',
registerType: claims ? 'autoUpdate' : 'prompt',
manifest: {
name: 'Vue App',
short_name: 'Vue App',
description: 'Bulletproof Vue 3 SPA Template',
theme_color: '#ffffff',
icons: [
{
src: 'pwa-64x64.png',
sizes: '64x64',
type: 'image/png',
},
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any',
},
{
src: 'maskable-icon-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
display_override: ['window-controls-overlay'],
},
devOptions: {
enabled: process.env.SW_DEV === 'true',
type: process.env.SW === 'true' ? 'module' : 'classic',
navigateFallbackAllowlist: [/^index.html$/],
},
workbox: {
globPatterns: [
'**/*.{html,css,js,json,txt,ico,svg,jpg,png,webp,woff,woff2,ttf,eot,otf,wasm}',
],
},
}
if (sw) {
pwaOptions.srcDir = 'src'
pwaOptions.strategies = 'injectManifest'
pwaOptions.filename = claims ? 'claims-sw.ts' : 'prompt-sw.ts';
(pwaOptions.manifest as Partial<ManifestOptions>).name
= 'PWA Inject Manifest';
(pwaOptions.manifest as Partial<ManifestOptions>).short_name = 'PWA Inject'
}
// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 3330,
},
build: {
sourcemap: process.env.SOURCE_MAP === 'true',
},
css: {
postcss: {
plugins: [tailwindNesting(), tailwind(), autoprefixer()],
},
},
plugins: [
tsconfigPaths({ loose: true }),
vue({
template: {
compilerOptions: {
isCustomElement: tag => ['my-counter', 'dark-mode-switch'].includes(tag),
},
},
}),
visualizer({
filename: 'html/visualizer-stats.html',
}) as unknown as PluginOption,
VitePWA(pwaOptions),
replace({
__DATE__: new Date().toISOString(),
__RELOAD_SW__: process.env.RELOAD_SW === 'true' ? 'true' : 'false',
}) as unknown as PluginOption,
],
test: {
root: fileURLToPath(new URL('./', import.meta.url)),
// to see how your tests are running in real time in the terminal, add "default"
// to generate HTML output and preview the results of your tests, add "html"
reporters: ['default', 'html'],
environment: 'jsdom', // mocking the DOM API
globals: true, // use APIs globally like jest
// testTransformMode: { web: [/\.[jt]sx$/] },
testTransformMode: { web: ['/.[jt]sx$/'] },
setupFiles: ['src/setup-test.ts'],
exclude: [...configDefaults.exclude, 'e2e/*'],
coverage: {
provider: 'istanbul', // 'istanbul' / 'v8'
reporter: ['text', 'json', 'html'],
thresholds: {
statements: 50,
branches: 50,
functions: 50,
lines: 50,
},
exclude: [
'coverage/**',
'dist/**',
'packages/*/test{,s}/**',
'**/*.d.ts',
'cypress/**',
'test{,s}/**',
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}',
'**/__tests__/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}',
// above is default
'src/setup-test.ts',
'src/main.ts',
'src/mocks/**',
'src/assets/**',
'src/lib/**',
'src/i18n/**',
],
},
},
})