codesandbox-client
codesandbox-client copied to clipboard
feat: support tailwind.css external resourses for Sandpack
Complete Tailwind CSS Play CDN support in Sandpack Bundler
What kind of change does this PR introduce?
Adds complete support for Tailwind CSS Play CDN in Sandpack by properly handling custom Tailwind CSS configs.
What is the current behavior?
Currently, when importing Tailwind Play CDN via externalResources in Sandpack it is impossible to customize Tailwind globals.css config because Sandpack bundler doesn't set the expected type="text/tailwindcss" attribute of the <style>/` tags. This prevents the Tailwind Play CDN (https://cdn.tailwindcss.com) from compiling CSS with custom Tailwind config.
What is the new behavior?
The Sandbox bundler now correctly identifies Tailwind CSS external resourses and sets the expected type="text/tailwindcss" attribute when the external resource file name includes 'tailwind.css'.
This enables:
- Using custom
globals.tailwind.cssviaexternalResources - Using custom
tailwind.config.jsviaexternalResources
Steps to test
- Create a new project with Sandpack's. Pass
https://cdn.tailwindcss.comin Sandpack'sexternalResources - Pass custom
tailwind.config.jsfile to Sandpack'sexternalResources - Pass
globals.tailwind.cssto Sandpack'sexternalResourceswith custom TailwindCSS styles (same asglobals.cssin standard Tailwind projects) - Verify that TailwindCSS is loaded properly in Sandpack
- Verify that custom Tailwind styles work as expected
Checklist
- [x] Documentation
- [x] Testing
- [x] Ready to be merged
- [ ] Added myself to contributors table (N/A)
Additional Context
This feature is for developers who want to use Tailwind CSS in Sandpack with custom tailwind.config.js and custom globals.css. The Tailwind Play CDN requires type="text/tailwindcss" in <link>/<style> tags to support custom globals.css files, which this PR now supports.
Tailwind CDN docs: https://tailwindcss.com/docs/installation/play-cdn