woodpecker/web/vite.config.ts

95 lines
2.5 KiB
TypeScript
Raw Normal View History

import { readdirSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
import vue from '@vitejs/plugin-vue';
import type { Plugin } from 'vite';
import prismjs from 'vite-plugin-prismjs';
import WindiCSS from 'vite-plugin-windicss';
import svgLoader from 'vite-svg-loader';
2024-04-29 19:33:45 +00:00
import { defineConfig } from 'vitest/config';
function woodpeckerInfoPlugin(): Plugin {
2021-12-21 09:52:10 +00:00
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`.';
2021-12-21 09:52:10 +00:00
console.log(info);
},
};
}
function externalCSSPlugin(): Plugin {
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', ''));
return {
name: 'vue-i18n-supported-locales',
resolveId(id) {
if (id === virtualModuleId) {
return resolvedVirtualModuleId;
}
},
load(id) {
if (id === resolvedVirtualModuleId) {
return `export const SUPPORTED_LOCALES = ${JSON.stringify(filenames)}`;
}
},
};
})(),
WindiCSS(),
svgLoader(),
externalCSSPlugin(),
2021-12-21 09:52:10 +00:00
woodpeckerInfoPlugin(),
prismjs({
languages: ['yaml'],
}),
],
resolve: {
alias: {
'~/': `${path.resolve(__dirname, 'src')}/`,
},
},
2021-12-21 09:52:10 +00:00
logLevel: 'warn',
server: {
host: process.env.VITE_DEV_SERVER_HOST ?? '127.0.0.1',
2021-12-21 09:52:10 +00:00
port: 8010,
},
2024-04-29 19:33:45 +00:00
test: {
globals: true,
environment: 'jsdom',
},
});