Hangar/frontend-new/vite.config.ts

165 lines
4.3 KiB
TypeScript
Raw Normal View History

2022-02-28 01:29:58 +08:00
import VueI18n from "@intlify/vite-plugin-vue-i18n";
2022-02-13 02:24:05 +08:00
import Vue from "@vitejs/plugin-vue";
2022-02-28 01:29:58 +08:00
import LinkAttributes from "markdown-it-link-attributes";
import Prism from "markdown-it-prism";
import path from "node:path";
2022-02-13 02:24:05 +08:00
import IconsResolver from "unplugin-icons/resolver";
2022-02-28 01:29:58 +08:00
import Icons from "unplugin-icons/vite";
import Components from "unplugin-vue-components/vite";
import { defineConfig } from "vite";
import EslintPlugin from "vite-plugin-eslint";
2022-02-13 02:24:05 +08:00
import Markdown from "vite-plugin-md";
2022-02-28 01:29:58 +08:00
import Pages from "vite-plugin-pages";
2022-02-13 02:24:05 +08:00
import { VitePWA } from "vite-plugin-pwa";
2022-02-28 01:29:58 +08:00
import Layouts from "vite-plugin-vue-layouts";
import WindiCSS from "vite-plugin-windicss";
2022-02-13 02:24:05 +08:00
import viteSSR from "vite-ssr/plugin";
2022-02-28 01:29:58 +08:00
import prettier from "./src/plugins/prettier";
2022-02-13 02:24:05 +08:00
2022-02-13 18:56:14 +08:00
const proxyHost = process.env.proxyHost || "http://localhost:8080";
const authHost = process.env.authHost || "http://localhost:3001";
2022-02-13 02:24:05 +08:00
export default defineConfig({
resolve: {
alias: {
"~/": `${path.resolve(__dirname, "src")}/`,
},
},
plugins: [
viteSSR(),
Vue({
include: [/\.vue$/, /\.md$/],
}),
// https://github.com/hannoeru/vite-plugin-pages
Pages({
extensions: ["vue", "md"],
}),
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
Layouts(),
// https://github.com/antfu/vite-plugin-md
Markdown({
wrapperClasses: "prose prose-sm m-auto text-left",
headEnabled: true, // This relies on useHead
markdownItSetup(md) {
// https://prismjs.com/
md.use(Prism);
md.use(LinkAttributes, {
2022-02-13 18:56:14 +08:00
pattern: /^https?:\/\//,
attrs: {
target: "_blank",
rel: "noopener",
},
2022-02-13 02:24:05 +08:00
});
},
}),
2022-02-28 01:29:58 +08:00
// https://github.com/antfu/unplugin-vue-components
2022-02-13 02:24:05 +08:00
Components({
// we don't want to import components, just icons
dirs: ["none"],
2022-02-13 02:24:05 +08:00
// auto import icons
resolvers: [
// https://github.com/antfu/vite-plugin-icons
IconsResolver({
2022-02-15 22:17:08 +08:00
componentPrefix: "icon",
2022-02-28 01:29:58 +08:00
enabledCollections: ["mdi"],
2022-02-13 02:24:05 +08:00
}),
],
2022-02-28 01:29:58 +08:00
dts: "src/types/generated/icons.d.ts",
2022-02-13 02:24:05 +08:00
}),
2022-02-28 01:29:58 +08:00
// https://github.com/antfu/unplugin-icons
2022-02-13 02:24:05 +08:00
Icons({
2022-02-13 18:56:14 +08:00
autoInstall: true,
2022-02-13 02:24:05 +08:00
}),
2022-02-28 01:29:58 +08:00
// https://github.com/windicss/vite-plugin-windicss
2022-02-13 02:24:05 +08:00
WindiCSS({
safelist: "prose prose-sm m-auto",
}),
// https://github.com/antfu/vite-plugin-pwa
VitePWA({
2022-02-13 18:56:14 +08:00
includeAssets: ["favicon/*"],
strategies: "injectManifest",
disable: true,
2022-02-13 02:24:05 +08:00
manifest: {
name: "Hangar | PaperMC",
short_name: "Hangar",
description: "Plugin repository for Paper plugins and more!",
theme_color: "#ffffff",
icons: [
{
2022-02-13 18:56:14 +08:00
src: "/favicon/android-chrome-192x192.png",
2022-02-13 02:24:05 +08:00
sizes: "192x192",
type: "image/png",
},
{
2022-02-13 18:56:14 +08:00
src: "/favicon/android-chrome-512x512.png",
2022-02-13 02:24:05 +08:00
sizes: "512x512",
type: "image/png",
},
{
2022-02-13 18:56:14 +08:00
src: "/favicon/android-chrome-512x512.png",
2022-02-13 02:24:05 +08:00
sizes: "512x512",
type: "image/png",
purpose: "any maskable",
},
],
},
}),
2022-02-28 01:29:58 +08:00
// https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
2022-02-13 02:24:05 +08:00
VueI18n({
2022-02-13 18:56:14 +08:00
include: [path.resolve(__dirname, "src/i18n/locales/*.json")],
2022-02-13 02:24:05 +08:00
}),
EslintPlugin({
2022-02-13 18:56:14 +08:00
fix: true,
2022-02-13 02:24:05 +08:00
}),
2022-02-28 01:29:58 +08:00
prettier(),
2022-02-13 02:24:05 +08:00
],
optimizeDeps: {
2022-02-13 18:56:14 +08:00
include: ["vue", "vue-router", "@vueuse/core", "@vueuse/head"],
exclude: ["vue-demi"],
2022-02-13 02:24:05 +08:00
},
envDir: ".env",
envPrefix: "HANGAR",
2022-02-13 02:24:05 +08:00
server: {
2022-02-13 18:56:14 +08:00
proxy: {
// backend
"/api/": proxyHost,
"/signup": proxyHost,
"/login": proxyHost,
"/logout": proxyHost,
"/handle-logout": proxyHost,
"/refresh": proxyHost,
"/invalidate": proxyHost,
"/v2/api-docs/": proxyHost,
"/robots.txt": proxyHost,
"/sitemap.xml": proxyHost,
"/global-sitemap.xml": proxyHost,
"/*/sitemap.xml": proxyHost,
"/statusz": proxyHost,
// auth
"/avatar": authHost,
"/oauth/logout": authHost,
"/oauth2": authHost,
},
},
// ssr options aren't part of release types for vite cause its still marked as experimental
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
ssr: {
noExternal: ["lodash-es"],
},
2022-02-13 02:24:05 +08:00
});