From cb2734e9a6c5deaea6e6b1a455cea393e0e616e0 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 21 Jun 2024 15:51:57 +0100 Subject: [PATCH] factor out plugin call this will make it easier to do per-file replacements --- packages/frontend/vite.config.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/frontend/vite.config.ts b/packages/frontend/vite.config.ts index 0824f1645f..63149e3e2c 100644 --- a/packages/frontend/vite.config.ts +++ b/packages/frontend/vite.config.ts @@ -1,5 +1,6 @@ import path from 'path'; import pluginReplace from '@rollup/plugin-replace'; +import type { RollupReplaceOptions } from '@rollup/plugin-replace'; import pluginVue from '@vitejs/plugin-vue'; import { type UserConfig, defineConfig } from 'vite'; @@ -59,6 +60,17 @@ function toBase62(n: number): string { return result; } +function iconsReplace(opts: RollupReplaceOptions) { + return pluginReplace({ + ...opts, + preventAssignment: false, + // only replace these strings after a quote, remove a ` ti-fw` + // it if happens to be just after, and make sure they're + // followed by a word-boundary that's not a dash + delimiters: ['(?<=["\'])', '(?: ti-fw)?\\b(?!-)'], + }); +} + export function getConfig(): UserConfig { return { base: '/vite/', @@ -71,12 +83,7 @@ export function getConfig(): UserConfig { pluginVue(), pluginUnwindCssModuleClassName(), pluginJson5(), - pluginReplace({ - preventAssignment: false, - // only replace these strings after a quote, remove a ` ti-fw` - // it if happens to be just after, and make sure they're - // followed by a word-boundary that's not a dash - delimiters: ['(?<=["\'])', '(?: ti-fw)?\\b(?!-)'], + iconsReplace({ values: { 'ti ti-terminal-2': 'ph-terminal-window ph-bold ph-lg', 'ti ti-download': 'ph-download ph-bold ph-lg',