forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mjs
162 lines (146 loc) · 4.7 KB
/
vite.config.mjs
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// @ts-check
import path from 'path'
import { fileURLToPath } from 'url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { vueI18n } from '@intlify/vite-plugin-vue-i18n'
import VueSvgLoader from 'vite-svg-loader'
import { CyCSSVitePlugin } from '@cypress-design/css'
import Components from 'unplugin-vue-components/vite'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
import PkgConfig from 'vite-plugin-package-config'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const base = './'
const alias = {
'@cy/components': path.resolve(__dirname, './src/components'),
'@cy/gql-components': path.resolve(__dirname, './src/gql-components'),
// import { defaultMessages, useI18n } from '@cy/i18n'
'@cy/i18n': path.resolve(__dirname, './src/locales/i18n'),
}
const makePlugins = (plugins) => {
return ([
vue(),
vueJsx(), // Used mostly for testing in *.(t|j)sx files.
vueI18n({
include: path.resolve(__dirname, './src/locales/**'),
...plugins.vueI18nOptions,
}),
Icons({
// 1em. Default, without this options is 1.2em.
// If you notice that your icons are bigger than they should be, this
// is probably why.
scale: 1,
customCollections: {
// ~icons/cy/book_x16
cy: FileSystemIconLoader(path.resolve(__dirname, './src/assets/icons')),
...plugins.iconsOptions?.customCollections,
},
iconCustomizer (collection, icon, props) {
if (icon.includes('_x')) {
const [, size] = icon.split('_x')
if (Number(size)) {
props.style = `min-width: ${size}px; min-height: ${size}px`
}
}
},
...plugins.iconsOptions,
}),
Components({
resolvers: IconsResolver({
// <i-cy-book_x16/>
customCollections: ['cy'],
}),
...plugins?.componentsOptions,
}),
CyCSSVitePlugin({
scan: {
// accepts globs and file paths relative to project root
include: [
'index.html',
'**/*.{vue,html,tsx}',
path.resolve(__dirname, '../frontend-shared/**/*.{vue,html,tsx,svg}'),
path.resolve(__dirname, '../app/**/*.{vue,html,tsx,svg}'),
path.resolve(__dirname, '../launchpad/**/*.{vue,html,tsx,svg}'),
],
exclude: ['node_modules/**/*', '.git/**/*'],
},
}),
VueSvgLoader(),
// package.json is modified and auto-updated when new cjs dependencies
// are added
PkgConfig.default(),
// OptimizationPersist(),
// For new plugins only! Merge options for shared plugins via PluginOptions.
...(plugins?.plugins || []),
])
}
/**
* @typedef PluginOptions
* @type {object}
* @property {import('@antfu/utils').ArgumentsType<typeof vueI18n>[0]=} vueI18nOptions
* @property {import('@antfu/utils').ArgumentsType<typeof Icons>[0]=} VueI18n
* @property {import('@antfu/utils').ArgumentsType<typeof Components>[0]=} componentOptions
*
* @param {import('vite').UserConfig} config
* @param {PluginOptions} plugins
* @returns {import('vite').UserConfig}
*/
export const makeConfig = (config = {}, plugins = {}) => {
// Don't overwrite plugins
delete config.plugins
return {
base,
publicDir: path.resolve(__dirname, './src/public'),
// Production-only build options
build: {
minify: false,
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "file:///${path.resolve(__dirname, '../reporter/src/lib/variables.scss').replaceAll('\\', '/')}" as *;\n`,
},
},
},
resolve: {
alias,
dedupe: [
'vue',
'@vue/compiler-core',
'@vue/compiler-dom',
'@vue/compiler-sfc',
'@vueuse/core',
'@urql/core',
'@urql/devtools',
'@urql/exchange-execute',
'@urql/exchange-graphcache',
'@urql/vue',
],
},
server: {
fs: {
// Since we're in a monorepo, we're going to serve packages from
// npm/vue/dist/* and other local places. This enables us to do that.
// https://vitejs.dev/config/#server-fs-strict
strict: false,
},
},
// You cannot add or remove arbitrary options from shared plugins.
// Please use the PluginsOverride option for this.
plugins: makePlugins(plugins),
define: {
'process.env': {
CYPRESS_INTERNAL_ENV: 'development',
},
// Fix to get cypress-plugin-tab to work in CT
'process.version': '99',
'setImmediate': {},
},
...config,
}
}
export default defineConfig(makeConfig())