2021-11-03 16:40:31 +00:00
|
|
|
/* eslint-disable import/no-extraneous-dependencies */
|
2023-03-19 23:07:18 +00:00
|
|
|
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
|
2021-11-03 16:40:31 +00:00
|
|
|
import vue from '@vitejs/plugin-vue';
|
2023-08-03 17:25:12 +00:00
|
|
|
import { copyFile, existsSync, mkdirSync, readdirSync } from 'fs';
|
2021-11-03 16:40:31 +00:00
|
|
|
import path from 'path';
|
|
|
|
import IconsResolver from 'unplugin-icons/resolver';
|
|
|
|
import Icons from 'unplugin-icons/vite';
|
|
|
|
import Components from 'unplugin-vue-components/vite';
|
|
|
|
import { defineConfig } from 'vite';
|
2022-08-09 15:39:45 +00:00
|
|
|
import prismjs from 'vite-plugin-prismjs';
|
2021-11-03 16:40:31 +00:00
|
|
|
import WindiCSS from 'vite-plugin-windicss';
|
|
|
|
import svgLoader from 'vite-svg-loader';
|
|
|
|
|
2021-12-21 09:52:10 +00:00
|
|
|
function woodpeckerInfoPlugin() {
|
|
|
|
return {
|
|
|
|
name: 'woodpecker-info',
|
|
|
|
configureServer() {
|
|
|
|
const info =
|
2023-07-16 19:31:36 +00:00
|
|
|
'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
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(info);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-03 16:40:31 +00:00
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
|
|
|
plugins: [
|
|
|
|
vue(),
|
2023-03-19 23:07:18 +00:00
|
|
|
VueI18nPlugin({
|
2022-05-16 19:18:48 +00:00
|
|
|
include: path.resolve(__dirname, 'src/assets/locales/**'),
|
|
|
|
}),
|
2022-12-29 12:41:59 +00:00
|
|
|
(() => {
|
|
|
|
const virtualModuleId = 'virtual:vue-i18n-supported-locales';
|
|
|
|
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
|
|
|
|
|
|
const filenames = readdirSync('src/assets/locales/').map((filename) => filename.replace('.json', ''));
|
|
|
|
|
2023-08-03 17:25:12 +00:00
|
|
|
if (!existsSync('src/assets/timeAgoLocales')) {
|
|
|
|
mkdirSync('src/assets/timeAgoLocales');
|
|
|
|
}
|
|
|
|
|
|
|
|
filenames.forEach((name) => {
|
|
|
|
// copy timeAgo language
|
|
|
|
if (name === 'zh-Hans') {
|
|
|
|
// zh-Hans is called zh in javascript-time-ago, so we need to rename this
|
|
|
|
copyFile(
|
|
|
|
'node_modules/javascript-time-ago/locale/zh.json.js',
|
|
|
|
'src/assets/timeAgoLocales/zh-Hans.js',
|
|
|
|
// eslint-disable-next-line promise/prefer-await-to-callbacks
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else if (name !== 'en') {
|
|
|
|
// English is always directly loaded (compiled by Vite) and thus not copied
|
|
|
|
copyFile(
|
|
|
|
`node_modules/javascript-time-ago/locale/${name}.json.js`,
|
|
|
|
`src/assets/timeAgoLocales/${name}.js`,
|
|
|
|
// eslint-disable-next-line promise/prefer-await-to-callbacks
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-12-29 12:41:59 +00:00
|
|
|
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)}`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
})(),
|
2021-11-03 16:40:31 +00:00
|
|
|
WindiCSS(),
|
2022-12-29 12:41:59 +00:00
|
|
|
Icons({}),
|
2021-11-03 16:40:31 +00:00
|
|
|
svgLoader(),
|
|
|
|
Components({
|
2022-12-29 12:41:59 +00:00
|
|
|
resolvers: [IconsResolver()],
|
2021-11-03 16:40:31 +00:00
|
|
|
}),
|
2021-12-21 09:52:10 +00:00
|
|
|
woodpeckerInfoPlugin(),
|
2022-08-09 15:39:45 +00:00
|
|
|
prismjs({
|
|
|
|
languages: ['yaml'],
|
|
|
|
}),
|
2021-11-03 16:40:31 +00:00
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'~/': `${path.resolve(__dirname, 'src')}/`,
|
|
|
|
},
|
|
|
|
},
|
2021-12-21 09:52:10 +00:00
|
|
|
logLevel: 'warn',
|
|
|
|
server: {
|
2023-07-16 19:31:36 +00:00
|
|
|
host: process.env.VITE_DEV_SERVER_HOST || '127.0.0.1',
|
2021-12-21 09:52:10 +00:00
|
|
|
port: 8010,
|
|
|
|
},
|
2021-11-03 16:40:31 +00:00
|
|
|
});
|