-
Notifications
You must be signed in to change notification settings - Fork 40
/
vite.config.ts
141 lines (138 loc) · 3.65 KB
/
vite.config.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/// <reference types="vitest" />
import { defineConfig } from 'vite'
import * as path from 'path'
import packageJson from './package.json'
import { VitePWA } from 'vite-plugin-pwa'
import VuePlugin from '@vitejs/plugin-vue'
import brotli from 'rollup-plugin-brotli'
import svgLoader from 'vite-svg-loader'
import { Agent as HttpsAgent } from 'https'
import webManifest from './webmanifest'
import { DEV_SERVER_PROXY_HOST } from './dev.config'
import browserslist from 'browserslist'
import { resolveToEsbuildTarget } from 'esbuild-plugin-browserslist'
import GithubActionsReporter from 'vitest-github-actions-reporter'
import autoprefixer from 'autoprefixer'
const keepAliveAgent = new HttpsAgent({ keepAlive: true })
export default defineConfig(({ command, mode }) => ({
resolve: {
alias: {
'/@': path.resolve(__dirname, 'src')
}
},
server: {
port: 8080,
proxy: {
'/api/v3': {
target: DEV_SERVER_PROXY_HOST,
changeOrigin: true,
ws: true,
agent: keepAliveAgent
},
'/api/auth': {
target: DEV_SERVER_PROXY_HOST,
changeOrigin: true,
ws: true,
agent: keepAliveAgent
}
}
},
build: {
target: resolveToEsbuildTarget(browserslist(), {
printUnknownTargets: false
}),
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules/katex')) return 'katex'
if (['@traptitech/traq/', 'axios'].some(t => id.includes(t))) {
return 'apis'
}
const hljsLangs = 'node_modules/highlight.js/lib/languages/'
const hljsLangIndex = id.indexOf(hljsLangs)
if (id.includes(hljsLangs)) {
// hljsは適当に二つに分割する
const firstLetter = id[hljsLangIndex + hljsLangs.length]
if (firstLetter < 'i') {
return 'hljs'
}
if (firstLetter < 'r') {
return 'hljs2'
}
return 'hljs3'
}
}
}
}
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
additionalData: `
@use "sass:math";
@use "/@/styles/common.scss" as *;
`,
charset: false
}
},
postcss: {
plugins: mode === 'production' ? [autoprefixer()] : []
},
devSourcemap: true
},
// /@/lib/define.tsを参照
define: {
__VERSION__: JSON.stringify(mode === 'test' ? 'test' : packageJson.version),
__DEV_SERVER__: JSON.stringify(
mode === 'development' ? DEV_SERVER_PROXY_HOST : ''
)
},
json: {
stringify: true
},
plugins: [
VitePWA({
strategies: 'injectManifest',
manifest: webManifest,
injectRegister: null,
srcDir: 'src',
filename: 'sw.ts',
includeAssets: ['fonts/*.woff2'],
injectManifest: {
globPatterns: ['**/*.{js,css,html}' /* default */, '**/assets/**/*.svg']
}
}),
VuePlugin(),
svgLoader({
defaultImport: 'component',
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
convertColors: {
currentColor: true
}
}
}
},
'removeDimensions'
]
}
}),
brotli()
],
test: {
include: ['tests/unit/**/*.spec.ts'],
globals: true,
setupFiles: ['tests/unit/setup.ts', 'tests/unit/expectExtends.ts'],
environment: 'jsdom',
reporters: process.env.CI ? new GithubActionsReporter() : 'default',
coverage: {
reporter: ['text', 'lcov']
}
}
}))