Search code examples
javascripttailwind-cssvitesveltekit

Referencing TailwindCSS config from JavaScript in SvelteKit


I'm using SvelteKit, which uses Vite and the setup instructions calls for CommonJS config files: https://tailwindcss.com/docs/guides/sveltekit

However, the guide for referencing the configuration in JavaScript requires ESM. https://tailwindcss.com/docs/configuration#referencing-in-java-script

Attempting to change the tailwind.config.cjs to ESM doesn't work (I get errors from other libraries trying to require() it as CJS).

Does anyone know how I can either get a working ESM tailwind.config.js in SvelteKit or a different better method to reference the tailwind config?


Solution

  • In case anyone is interested, I resorted to writing my definitions in a separate .json file.

    I then import that into the Tailwind config file, and also import those definitions elsewhere where I need them (as json).