-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
81 lines (74 loc) · 2.07 KB
/
Copy pathvite.config.js
File metadata and controls
81 lines (74 loc) · 2.07 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
import { defineConfig } from 'vite'
import { resolve, dirname } from 'path'
import { fileURLToPath } from 'url'
import { copyFileSync, existsSync, mkdirSync } from 'fs'
import { globSync } from 'glob'
import liveReload from 'vite-plugin-live-reload'
const __dirname = dirname(fileURLToPath(import.meta.url))
export default defineConfig({
publicDir: false,
plugins: [
liveReload([
'resources/views/**/*.twig',
'app/**/*.php'
]),
{
name: 'copy-images',
writeBundle() {
const srcDir = 'resources/assets/src/images'
const destDir = 'resources/assets/dist/images'
if (!existsSync(destDir)) {
mkdirSync(destDir, { recursive: true })
}
const files = globSync(`${srcDir}/**/*`, { nodir: true })
files.forEach(file => {
const relativePath = file.replace(srcDir + '/', '')
const destFile = `${destDir}/${relativePath}`
const destFileDir = dirname(destFile)
if (!existsSync(destFileDir)) {
mkdirSync(destFileDir, { recursive: true })
}
copyFileSync(file, destFile)
})
}
}
],
build: {
outDir: 'resources/assets/dist',
emptyOutDir: false,
cssMinify: 'lightningcss',
rollupOptions: {
input: {
app: resolve(__dirname, 'resources/assets/src/scripts/app.js'),
styles: resolve(__dirname, 'resources/assets/src/styles/bundle.scss')
},
output: {
entryFileNames: 'js/[name].min.js',
assetFileNames: assetInfo => {
if (assetInfo.names?.[0]?.endsWith('.css')) {
return 'css/bundle.min.css'
}
if (assetInfo.names?.[0]?.match(/\.(png|jpe?g|svg|gif|webp|ico)$/)) {
return 'images/[name][extname]'
}
return 'assets/[name][extname]'
}
}
}
},
css: {
transformer: 'lightningcss',
lightningcss: {
targets: {
chrome: 100,
firefox: 100,
safari: 15
}
},
preprocessorOptions: {
scss: {
api: 'modern-compiler'
}
}
}
})