From efe32e86c90c0559d4a28f45d1aad2443131dc53 Mon Sep 17 00:00:00 2001 From: Athou Date: Tue, 27 Jun 2023 19:23:13 +0200 Subject: [PATCH] remove warning about vite not finding custom code at build time --- commafeed-client/index.html | 2 -- commafeed-client/vite.config.ts | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/commafeed-client/index.html b/commafeed-client/index.html index fca20ffa..8f5a5e3e 100644 --- a/commafeed-client/index.html +++ b/commafeed-client/index.html @@ -4,13 +4,11 @@ - CommaFeed
- diff --git a/commafeed-client/vite.config.ts b/commafeed-client/vite.config.ts index e1e17507..5c740258 100644 --- a/commafeed-client/vite.config.ts +++ b/commafeed-client/vite.config.ts @@ -1,13 +1,41 @@ import { lingui } from "@lingui/vite-plugin" import react from "@vitejs/plugin-react" import { visualizer } from "rollup-plugin-visualizer" -import { defineConfig } from "vite" +import { defineConfig, PluginOption } from "vite" import eslint from "vite-plugin-eslint" import tsconfigPaths from "vite-tsconfig-paths" +// 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", + }, + ], + } + }, +} + // https://vitejs.dev/config/ export default defineConfig({ plugins: [ + customCodeInjector, react({ babel: { // babel-macro is needed for lingui