-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathvite.config.mjs
More file actions
90 lines (81 loc) · 2.54 KB
/
Copy pathvite.config.mjs
File metadata and controls
90 lines (81 loc) · 2.54 KB
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
import { defineConfig } from 'vite'
import symfony from 'vite-plugin-symfony'
import path from 'node:path'
import { jsEntries, cssEntries } from './vite/entries.mjs'
import { purgeCssPlugin, cssEntryWrappers, staticCopy } from './vite/plugins.mjs'
const rootDir = import.meta.dirname
const ASSET_DIRS = {
'.css': 'css',
'.woff': 'fonts',
'.woff2': 'fonts',
'.ttf': 'fonts',
'.otf': 'fonts',
'.eot': 'fonts',
'.png': 'images',
'.jpg': 'images',
'.jpeg': 'images',
'.gif': 'images',
'.svg': 'images',
'.webp': 'images',
'.ico': 'images',
}
export default defineConfig(({ mode }) => {
const themes = cssEntryWrappers(cssEntries, { rootDir })
return {
base: '/build/',
publicDir: false,
resolve: {
alias: { '@': path.resolve(rootDir, 'assets') },
},
build: {
outDir: 'public/build',
emptyOutDir: true,
manifest: true,
// 'hidden' in prod: maps are emitted (so upload-sourcemaps can ship
// them to Bugsnag) but the JS bundles carry no sourceMappingURL, so
// the browser doesn't expose them publicly.
sourcemap: mode === 'production' ? 'hidden' : true,
rollupOptions: {
input: { ...jsEntries, ...themes.input },
output: {
entryFileNames: 'js/[name]-[hash].js',
chunkFileNames: 'js/chunks/[name]-[hash].js',
assetFileNames: (info) => {
const dir = ASSET_DIRS[path.extname(info.name || '').toLowerCase()] ?? 'assets'
return `${dir}/[name]-[hash][extname]`
},
},
},
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
api: 'modern-compiler',
// Bootstrap 5 Sass deprecations — drop on Bootstrap 6 upgrade.
silenceDeprecations: ['import', 'global-builtin', 'color-functions', 'if-function'],
loadPaths: [path.resolve(rootDir, 'node_modules')],
},
},
},
plugins: [
themes.plugin,
purgeCssPlugin({ rootDir }),
// Twig references images via asset('images/...'); land them at
// public/images/ (= one level up from build.outDir) so the URL resolves
// without bundler involvement. webp-on-demand.php writes generated
// variants alongside.
staticCopy(
[
{ src: 'assets/images', dest: '../images' },
{ src: 'assets/images/favicon.ico', dest: '../favicon.ico' },
],
{ rootDir },
),
symfony({
stimulus: './assets/controllers.json',
viteDevServerHostname: 'localhost',
}),
],
}
})