diff --git a/next-themes/src/index.tsx b/next-themes/src/index.tsx index fd03ad7..5757521 100644 --- a/next-themes/src/index.tsx +++ b/next-themes/src/index.tsx @@ -1,9 +1,12 @@ 'use client' import * as React from 'react' -import { script } from './script' import type { Attribute, ThemeProviderProps, UseThemeProps } from './types' +// @ts-ignore +import scriptTemplate from './script.template.js'; +const scriptText = scriptTemplate as string; + const colorSchemes = ['light', 'dark'] const MEDIA = '(prefers-color-scheme: dark)' const isServer = typeof window === 'undefined' @@ -213,7 +216,7 @@ const ThemeScript = React.memo( {...scriptProps} suppressHydrationWarning nonce={typeof window === 'undefined' ? nonce : ''} - dangerouslySetInnerHTML={{ __html: `(${script.toString()})(${scriptArgs})` }} + dangerouslySetInnerHTML={{ __html: `(${scriptText})(${scriptArgs})` }} /> ) } diff --git a/next-themes/src/script.ts b/next-themes/src/script.template.js similarity index 92% rename from next-themes/src/script.ts rename to next-themes/src/script.template.js index 05bfbc0..e8f73ac 100644 --- a/next-themes/src/script.ts +++ b/next-themes/src/script.template.js @@ -1,4 +1,4 @@ -export const script = ( +( attribute, storageKey, defaultTheme, @@ -11,7 +11,7 @@ export const script = ( const el = document.documentElement const systemThemes = ['light', 'dark'] - function updateDOM(theme: string) { + function updateDOM(theme) { const attributes = Array.isArray(attribute) ? attribute : [attribute] attributes.forEach(attr => { @@ -28,7 +28,7 @@ export const script = ( setColorScheme(theme) } - function setColorScheme(theme: string) { + function setColorScheme(theme) { if (enableColorScheme && systemThemes.includes(theme)) { el.style.colorScheme = theme } diff --git a/next-themes/tsup.config.ts b/next-themes/tsup.config.ts index fd39d1b..213eb5b 100644 --- a/next-themes/tsup.config.ts +++ b/next-themes/tsup.config.ts @@ -9,5 +9,8 @@ export default defineConfig({ external: ['react'], format: ['esm', 'cjs'], splitting: false, - bundle: true + bundle: true, + loader: { + '.template.js': 'text' + }, })