-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.js
110 lines (105 loc) · 3.03 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
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
import path from 'node:path'
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import { createHtmlPlugin } from 'vite-plugin-html'
// https://vitejs.dev/config/
/** @type {import('vite').UserConfig} */
export default ({ command, mode }) => {
const root = process.cwd()
const folderName = path.basename(root)
// append folder name to base path if using GitHub/GitLab repo pages
const usingRepoPages = !process.env.VITE_ROOT_PAGES
const base = mode === 'production' && usingRepoPages ? `/${folderName}/` : '/'
const isBuild = command === 'build'
console.log('Configuring with...', {
command,
mode,
usingRepoPages,
root,
folderName,
base
})
return defineConfig({
root,
base,
mode,
plugins: [
react(),
createHtmlPlugin({
minify: isBuild,
inject: {
// Inject data into ejs template
data: {
PUBLIC_URL: base,
TITLE: 'OMDb Search',
DESCRIPTION:
'Search for movies, TV shows, Series, Episodes and Games using the OMDb API',
KEYWORDS:
'IMDb,OMDb,OMDb API,search,api,react,vite,application,games,movies,series,anime,documentary,short,video,game,episode,episodes,app,web,website,web app',
THEME_COLOR: '#0068b5'
}
}
})
],
test: {
coverage: {
provider: 'c8',
reportsDirectory: './target/coverage',
reporter: [
'json',
'json-summary',
'lcovonly',
'text',
'text-summary',
'clover',
'cobertura'
]
},
environment: 'node',
environmentMatchGlobs: [
// all tests in __tests__/ with .XXX.test.js will run in that environment
['**/*.*dom.test.js', 'jsdom'],
['**/*.*dom.test.jsx', 'jsdom'],
['**/*.*dom.spec.js', 'jsdom'],
['**/*.*dom.spec.jsx', 'jsdom']
// ...
],
globals: true,
setupFiles: [
// setup files for all tests
'./__tests__/setup-tests.js'
]
},
build: {
outDir: 'dist',
emptyOutDir: true
},
resolve: {
alias: {
'@': srcAliasOf(),
'@components': srcAliasOf('components'),
'@context': srcAliasOf('context'),
'@hooks': srcAliasOf('hooks'),
'@services': srcAliasOf('services'),
'@shared': srcAliasOf('shared')
}
},
server: {
watch: {
ignored: [
`**/${folderName}/__test__/**`, // ignore test folder
`**/${folderName}/target/**`, // ignore 3th-party output
`**/${folderName}/docs/**`, // ignore docs folder
`**/${folderName}/src-docs/**`, // ignore src-docs folder
`**/${folderName}/jsdoc.json`, // ignore jsdoc config
`**/${folderName}/README.md` // ignore jsdoc config
]
}
}
})
}
function srcAliasOf(slug = '') {
const url = new URL('./src/' + slug, import.meta.url)
return fileURLToPath(url)
}