-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
92 lines (84 loc) · 2.28 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
/* eslint-disable @typescript-eslint/no-explicit-any */
import { resolve } from 'path'
import { defineConfig, normalizePath } from 'vite'
import manifestSRI from 'vite-plugin-manifest-sri'
import critical from 'rollup-plugin-critical'
import legacy from '@vitejs/plugin-legacy'
import ViteRestart from 'vite-plugin-restart'
import { ViteFaviconsPlugin } from 'vite-plugin-favicon2'
const nPath = path => normalizePath(resolve(__dirname, path))
const criticalUrl = process.env.CRITICAL_URL || false
const ddevUrl = process.env.DDEV_PRIMARY_URL || 'http://localhost'
const ddevVitePort = parseInt(process.env.VITE_PRIMARY_PORT || '5173')
let plugins = [
manifestSRI(),
legacy({
targets: ['defaults', 'not IE 11']
}),
/*
Using undocumented "reload" prop instead "restart" for
faster developement. Check:
https://github.com/antfu/vite-plugin-restart/blob/main/src/index.ts#L25
*/
(ViteRestart as any).default({ reload: ['./cms/templates/**/*'] }),
ViteFaviconsPlugin({
logo: nPath('./src/static/favicon.svg'),
inject: false,
outputPath: 'favicons',
favicons: {
start_url: '/'
}
})
]
if (criticalUrl !== false) {
plugins = [
...plugins,
(critical as any).default({
criticalUrl: criticalUrl,
criticalBase: nPath('./cms/web/dist/criticalcss/'),
criticalPages: [
{
uri: '/',
template: 'index'
}
],
criticalConfig: {
base: nPath('./cms/web/dist/criticalcss/'),
extract: true,
dimensions: [
{ width: 1300, height: 900 },
{ width: 414, height: 896 },
{ width: 375, height: 667 }
]
}
})
]
}
export default defineConfig(({ command }) => ({
base: command === 'serve' ? '' : `/dist/`,
publicDir: nPath('./src/static'),
build: {
emptyOutDir: true,
manifest: 'vite-manifest.json',
outDir: nPath('./cms/web/dist'),
rollupOptions: {
input: {
app: nPath('./src/js/app.ts'),
'lazysizes-wrapper': nPath('./src/js/utils/lazysizes-wrapper.ts')
},
output: {
sourcemap: true
}
}
},
plugins: [...plugins],
server: {
fs: {
strict: false
},
origin: `${ddevUrl}:${ddevVitePort}`,
host: '0.0.0.0',
port: ddevVitePort,
strictPort: true
}
}))