From 86564a5af9bfdf5c4ac1a8ec4ffbc53ca80a93fd Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Mon, 17 Feb 2025 14:30:32 +0900 Subject: [PATCH] Check browser --- .changeset/wild-pans-repair.md | 5 +++++ packages/vite-plugin/src/plugin.ts | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .changeset/wild-pans-repair.md diff --git a/.changeset/wild-pans-repair.md b/.changeset/wild-pans-repair.md new file mode 100644 index 00000000..74c414b1 --- /dev/null +++ b/.changeset/wild-pans-repair.md @@ -0,0 +1,5 @@ +--- +"@devup-ui/vite-plugin": patch +--- + +check browser diff --git a/packages/vite-plugin/src/plugin.ts b/packages/vite-plugin/src/plugin.ts index 35bd6864..0d19efb6 100644 --- a/packages/vite-plugin/src/plugin.ts +++ b/packages/vite-plugin/src/plugin.ts @@ -112,13 +112,15 @@ export function DevupUI({ if (command === 'serve') return { code: `${retCode} - const exists = !!document.getElementById('devup-ui'); - const style = document.getElementById('devup-ui') || document.createElement('style'); - style.id = 'devup-ui'; - style.textContent = \` - ${css} - \`; - if (!exists) document.head.appendChild(style); + if(typeof window !== 'undefined'){ + const exists = !!document.getElementById('devup-ui'); + const style = document.getElementById('devup-ui') || document.createElement('style'); + style.id = 'devup-ui'; + style.textContent = \` + ${css} + \`; + if (!exists) document.head.appendChild(style); + } `, } }