-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvite.config.js
executable file
·78 lines (61 loc) · 1.76 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
75
76
77
78
import { resolve, relative } from 'path'
import { defineConfig } from 'vite'
import { glob } from 'glob'
import handlebarsPlugin from 'vite-plugin-handlebars'
import hbsHelpers from './src/support/hbs-helpers'
import data from './src/data'
import { baseUrl } from './src/support'
const root = 'src/html'
const entries = () => {
const entries = {}
glob.sync(`${root}/**/*.html`).forEach((p) => {
let relPath = relative(root, p)
entries[relPath] = p
})
return entries
}
export default defineConfig({
plugins: [
handlebarsPlugin({
partialDirectory: [resolve(__dirname, 'src', 'html', 'hbs')],
context: {
...data,
env: process.env.NODE_ENV,
},
helpers: hbsHelpers,
}),
],
root,
base: baseUrl,
publicDir: resolve(__dirname, 'public'),
resolve: {
alias: {
'@/': resolve(__dirname, 'src'),
},
},
optimizeDeps: {
entries: Object.keys(entries()),
},
build: {
emptyOutDir: true,
target: 'esnext',
outDir: resolve(__dirname, 'dist'),
rollupOptions: {
input: entries(),
output: {
assetFileNames: (chunkInfo) => {
let outDir = ''
if (/css$/.test(chunkInfo.name)) {
outDir = 'css'
}
return `${outDir}/[name][extname]`
},
chunkFileNames: 'js/[name]-[hash].js',
entryFileNames: (e) => {
let name = e.name.split('/').pop().replace('.html', '-page')
return `js/${name}-[hash].js`
},
},
},
},
})