-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvite.config.js
74 lines (67 loc) · 1.7 KB
/
vite.config.js
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
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'
import vitePWA from 'vite-pwa'
import react from '@vitejs/plugin-react'
import viteVSCode from 'vite-vscode'
import svgr from '@honkhonk/vite-plugin-svgr'
const isDevMode = process.env.NODE_ENV !== 'production'
const srcDir = path.resolve('./src')
const config = {
static: 'static',
assets: 'assets',
}
const plugins = [
react(),
svgr.default(),
vitePWA({
map: true,
spa: true,
preCacheFiles: ['/', '/sw.js', '/swRegister.js', '/manifest.json'],
}),
viteVSCode(),
]
const css = {
modules: {
generateScopedName: isDevMode
? '[local]___[name]--[hash:base64:5]'
: '[hash:base64]',
},
preprocessorOptions: {
scss: {
additionalData: `@use '$styles/abstracts/core' as *;\n`,
},
},
}
const resolve = {
alias: {
$slice: path.join(srcDir, '/store/slice'),
$ui: path.join(srcDir, '/components/UI'),
...Object.fromEntries(
fs
.readdirSync(srcDir)
.filter((t) => fs.lstatSync(path.join(srcDir, t)).isDirectory())
.map((t) => [`$${t}`, path.join(srcDir, t)])
),
$src: srcDir,
},
}
const server = {
host: 'localhost',
port: 3000,
}
const build = {
rollupOptions: {
output: {
assetFileNames: (file) => {
const ext = file.name.split('.').at(-1)
const outputFolder =
ext === 'css' || ext === 'js' ? '' : config.assets + '/'
return `${config.static}/${outputFolder}[name]-[hash][extname]`
},
entryFileNames: `${config.static}/[name]-[hash].js`,
chunkFileNames: `${config.static}/chunk-[name]-[hash].js`,
},
},
}
export default defineConfig({ plugins, css, resolve, server, build })