-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.js
66 lines (63 loc) · 2.05 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
import {defineConfig} from 'vite'
import {ViteWebfontDownload} from 'vite-plugin-webfont-dl'
import {FontSubsetMaker, UnusedCodeRemover, ComlinkDevFirefox, HTMLBuildAttributes, ExtraAssetsServe} from './vite-plugins'
import {comlink} from 'vite-plugin-comlink'
import {version} from './package.json'
import {execSync} from 'child_process'
const DEBUG_IN_FIREFOX = true
const BUILD_ATTRIBUTES = {
BUILD_DATE: (new Date()).toLocaleDateString('en-GB'),
BUILD_VERSION: version
}
export default defineConfig(({command, mode}) => {
let cfg = {
root: 'src',
plugins: [
HTMLBuildAttributes(BUILD_ATTRIBUTES),
ViteWebfontDownload()
]
}
if (command === 'build') {
// production specific config
const COMMIT_HASH = execSync('git rev-parse --short HEAD').toString()
BUILD_ATTRIBUTES.BUILD_VERSION += `@${COMMIT_HASH.slice(0, 7)}`
cfg = {
...cfg,
build: {
outDir: '../dist'
},
plugins: [
...cfg.plugins,
comlink(),
// https://github.com/google/material-design-icons/blob/master/font/MaterialIcons-Regular.codepoints
FontSubsetMaker({
fontPath: 'src/lib/MaterialIcons-Regular.ttf',
searchPattern: /data-icon="([^"]+)"/gm,
codePoint: 'https://raw.githubusercontent.com/google/material-design-icons/master/font/MaterialIcons-Regular.codepoints',
extraIcons: 'smartphone tablet clear_all mode_comment book settings star star_border chevron_left chevron_right insert_link menu'.split(' ')
}),
UnusedCodeRemover([
{
name: 'material.light_green-blue',
ext: 'css',
hash: 'e4868944',
path: 'styles'
}
])
],
worker: {
plugins: [
comlink()
]
}
}
} else {
cfg.plugins.push(DEBUG_IN_FIREFOX ? ComlinkDevFirefox() : comlink())
cfg.publicDir = '../v2data/'
if (command === 'serve' && mode === 'production') {
cfg.plugins.push(ExtraAssetsServe('v2data', '/v2data'))
cfg.root = ''
}
}
return cfg
})