From 131a8ebf680cb99becdbd716f3e6f42c1247253b Mon Sep 17 00:00:00 2001 From: Athou Date: Tue, 11 Mar 2025 15:45:35 +0100 Subject: [PATCH] remove warning about vite not finding custom code at build time --- commafeed-client/index.html | 3 --- commafeed-client/vite.config.ts | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/commafeed-client/index.html b/commafeed-client/index.html index 2cc6a82c..a0b2c458 100644 --- a/commafeed-client/index.html +++ b/commafeed-client/index.html @@ -6,9 +6,6 @@ - - - CommaFeed diff --git a/commafeed-client/vite.config.ts b/commafeed-client/vite.config.ts index 22fc6c3f..accae95e 100644 --- a/commafeed-client/vite.config.ts +++ b/commafeed-client/vite.config.ts @@ -1,13 +1,14 @@ import { lingui } from "@lingui/vite-plugin" import react from "@vitejs/plugin-react" import { visualizer } from "rollup-plugin-visualizer" -import { defineConfig } from "vite" +import { type PluginOption, defineConfig } from "vite" import checker from "vite-plugin-checker" import tsconfigPaths from "vite-tsconfig-paths" // https://vitejs.dev/config/ export default defineConfig(() => ({ plugins: [ + customCodeInjector, react({ babel: { plugins: ["@lingui/babel-plugin-lingui-macro"], @@ -56,3 +57,30 @@ export default defineConfig(() => ({ setupFiles: "./src/setupTests.ts", }, })) + +// inject custom js and css links in html +const customCodeInjector: PluginOption = { + name: "customCodeInjector", + transformIndexHtml: html => { + return { + html, + tags: [ + { + tag: "script", + attrs: { + src: "custom_js.js", + }, + injectTo: "body", + }, + { + tag: "link", + attrs: { + rel: "stylesheet", + href: "custom_css.css", + }, + injectTo: "head", + }, + ], + } + }, +}