movie-web/vite.config.mts

175 lines
4.6 KiB
TypeScript
Raw Normal View History

2023-02-22 20:15:37 +00:00
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
2023-01-07 20:36:18 +00:00
import loadVersion from "vite-plugin-package-version";
2023-02-24 18:23:00 +00:00
import { VitePWA } from "vite-plugin-pwa";
import checker from "vite-plugin-checker";
2022-12-13 22:19:07 +00:00
import path from "path";
import million from 'million/compiler';
2023-07-15 13:53:43 +00:00
import { handlebars } from "./plugins/handlebars";
import { PluginOption, loadEnv, splitVendorChunkPlugin } from "vite";
import { visualizer } from "rollup-plugin-visualizer";
2022-12-13 22:19:07 +00:00
import tailwind from "tailwindcss";
import rtl from "postcss-rtlcss";
2023-12-24 03:14:34 +00:00
const captioningPackages = [
"dompurify",
"htmlparser2",
"subsrt-ts",
"parse5",
"entities",
"fuse"
];
2023-07-22 19:41:15 +00:00
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
return {
base: env.VITE_BASE_URL || '/',
plugins: [
million.vite({ auto: true, mute: true }),
handlebars({
vars: {
opensearchEnabled: env.VITE_OPENSEARCH_ENABLED === "true",
routeDomain:
env.VITE_APP_DOMAIN +
(env.VITE_NORMAL_ROUTER !== "true" ? "/#" : ""),
domain: env.VITE_APP_DOMAIN,
env,
},
}),
react({
babel: {
presets: [
"@babel/preset-typescript",
[
"@babel/preset-env",
{
modules: false,
useBuiltIns: "entry",
corejs: {
version: "3.34",
},
},
],
],
},
}),
VitePWA({
disable: env.VITE_PWA_ENABLED !== "true",
registerType: "autoUpdate",
workbox: {
maximumFileSizeToCacheInBytes: 4000000, // 4mb
globIgnores: ["**ping.txt**"],
},
includeAssets: [
"favicon.ico",
"apple-touch-icon.png",
"safari-pinned-tab.svg",
],
manifest: {
name: "movie-web",
short_name: "movie-web",
description: "The place for your favourite movies & shows",
theme_color: "#120f1d",
background_color: "#120f1d",
display: "standalone",
start_url: "/",
icons: [
{
src: "android-chrome-192x192.png",
sizes: "192x192",
type: "image/png",
purpose: "any",
},
{
src: "android-chrome-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
{
src: "android-chrome-192x192.png",
sizes: "192x192",
type: "image/png",
purpose: "maskable",
},
{
src: "android-chrome-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
}),
loadVersion(),
checker({
overlay: {
position: "tr",
},
typescript: true, // check typescript build errors in dev server
eslint: {
// check lint errors in dev server
lintCommand: "eslint --ext .tsx,.ts src",
dev: {
logLevel: ["error"],
},
},
}),
splitVendorChunkPlugin(),
visualizer() as PluginOption
],
2023-12-12 23:26:46 +00:00
build: {
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id: string) {
2024-01-03 19:43:28 +00:00
if (id.includes("@sozialhelden+ietf-language-tags") || id.includes("country-language")) {
return "language-db";
}
if (id.includes("hls.js")) {
return "hls";
}
2023-12-24 03:14:34 +00:00
if (id.includes("node-forge") || id.includes("crypto-js")) {
return "auth";
}
if (id.includes("locales") && !id.includes("en.json")) {
return "locales";
}
if (id.includes("react-dom")) {
return "react-dom";
}
2023-12-24 03:14:34 +00:00
if (id.includes("Icon.tsx")) {
return "Icons";
}
const isCaptioningPackage = captioningPackages.some(packageName => id.includes(packageName));
if (isCaptioningPackage) {
return "caption-parsing";
}
}
}
}
2023-12-12 23:26:46 +00:00
},
css: {
postcss: {
plugins: [tailwind(), rtl()],
},
},
2023-12-12 23:26:46 +00:00
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
"@sozialhelden/ietf-language-tags": path.resolve(
__dirname,
"./node_modules/@sozialhelden/ietf-language-tags/dist/cjs"
),
},
},
2023-02-22 20:15:37 +00:00
test: {
environment: "jsdom",
},
};
2022-12-13 22:19:07 +00:00
});