forked from hpidcock/woodpecker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
140 lines (131 loc) · 3.93 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
/* eslint-disable import/no-extraneous-dependencies */
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
import vue from '@vitejs/plugin-vue';
import { copyFile, existsSync, mkdirSync, readdirSync } from 'fs';
import path from 'path';
import replace from 'replace-in-file';
import IconsResolver from 'unplugin-icons/resolver';
import Icons from 'unplugin-icons/vite';
import Components from 'unplugin-vue-components/vite';
import prismjs from 'vite-plugin-prismjs';
import WindiCSS from 'vite-plugin-windicss';
import svgLoader from 'vite-svg-loader';
import { defineConfig } from 'vitest/config';
function woodpeckerInfoPlugin() {
return {
name: 'woodpecker-info',
configureServer() {
const info =
'1) Please add `WOODPECKER_DEV_WWW_PROXY=http://localhost:8010` to your `.env` file.\n' +
'After starting the woodpecker server as well you should now be able to access the UI at http://localhost:8000/\n\n' +
'2) If you want to run the vite dev server (`pnpm start`) within a container please set `VITE_DEV_SERVER_HOST=0.0.0.0`.';
// eslint-disable-next-line no-console
console.log(info);
},
};
}
function externalCSSPlugin() {
return {
name: 'external-css',
transformIndexHtml: {
order: 'post',
handler() {
return [
{
tag: 'link',
attrs: { rel: 'stylesheet', type: 'text/css', href: '/assets/custom.css' },
injectTo: 'head',
},
];
},
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
VueI18nPlugin({
include: path.resolve(__dirname, 'src/assets/locales/**'),
}),
(() => {
const virtualModuleId = 'virtual:vue-i18n-supported-locales';
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
const filenames = readdirSync('src/assets/locales/').map((filename) => filename.replace('.json', ''));
if (!existsSync('src/assets/dayjsLocales')) {
mkdirSync('src/assets/dayjsLocales');
}
filenames.forEach(async (name) => {
// English is always directly loaded (compiled by Vite) and thus not copied
if (name === 'en') {
return;
}
let langName = name;
// copy dayjs language
if (name === 'zh-Hans') {
// zh-Hans is called zh in dayjs
langName = 'zh';
} else if (name === 'zh-Hant') {
// zh-Hant is called zh-cn in dayjs
langName = 'zh-cn';
}
copyFile(
`node_modules/dayjs/esm/locale/${langName}.js`,
`src/assets/dayjsLocales/${name}.js`,
// eslint-disable-next-line promise/prefer-await-to-callbacks
(err) => {
if (err) {
throw err;
}
},
);
});
replace.sync({
files: 'src/assets/dayjsLocales/*.js',
// remove any dayjs import and any dayjs.locale call
from: /(?:import dayjs.*'|dayjs\.locale.*);/g,
to: '',
});
return {
name: 'vue-i18n-supported-locales',
// eslint-disable-next-line consistent-return
resolveId(id) {
if (id === virtualModuleId) {
return resolvedVirtualModuleId;
}
},
// eslint-disable-next-line consistent-return
load(id) {
if (id === resolvedVirtualModuleId) {
return `export const SUPPORTED_LOCALES = ${JSON.stringify(filenames)}`;
}
},
};
})(),
WindiCSS(),
Icons({}),
svgLoader(),
Components({
resolvers: [IconsResolver()],
}),
externalCSSPlugin(),
woodpeckerInfoPlugin(),
prismjs({
languages: ['yaml'],
}),
],
resolve: {
alias: {
'~/': `${path.resolve(__dirname, 'src')}/`,
},
},
logLevel: 'warn',
server: {
host: process.env.VITE_DEV_SERVER_HOST || '127.0.0.1',
port: 8010,
},
test: {
globals: true,
environment: 'jsdom',
},
});