Documentation needed for integration of Storybook + SvelteKit + Tailwind
See original GitHub issueIs your feature request related to a problem? Please describe A lot has improved about the way Storybook recognizes the context in which it is being installed and then installs itself. However, not only a new version of Svelte is out (with which Storybook doesn’t work out of the box) but integrating Tailwind keeps being cumbersome and needing a lot of research and trial and error.
According to The State of CSS 2019 and 2010, Tailwind is the most used CSS framework. Components that are styled with Tailwind need consequently to be shown in Storybook with the same styles. Having documentation that enabled integrating these three technologies without too much trouble would be extremely appreciated.
Describe the solution you’d like I would like to see:
- the Storybook installation script fixed for SvelteKit
- documentation about integration with Tailwind in place or even an addon to implement this integration easily
Are you able to assist to bring the feature to reality? Possibly, with documentation. In Additional context I report on the solution I’ve implemented so far, just as a temporary workaround.
Additional context Currently, the following seem to be the necessary steps to get these three technologies to play well together:
- Install a clean new SvelteKit app:
npm init svelte@nextfollowed bynpm i✔ Which Svelte app template? › SvelteKit demo app ✔ Use TypeScript? … No ✔ Add ESLint for code linting? … Yes ✔ Add Prettier for code formatting? › Yes - Install Storybook:
npx sb@next init.npx sb inityelds similar results. - Run Storybook:
npm run storybook. This fails with ESM errors. - Change the extensions of both
.storybook/main.jsand.storybook/preview.jsto.cjs. - Comment out
"preprocess": require("../svelte.config.js").preprocesswithinsvelteOptions. This and the previous step are documented as a workaround in Storybook cannot be built on packages using “type”: “module” #11587. - Add PostCSS to Svelte using the [Svelte corresponding adder](npx svelte-add postcss):
npx svelte-add postcssfollowed bynpm i. - Add Tailwind CSS to Svelte using the Svelte corresponding adder:
npx svelte-add tailwindcssfollowed bynpm i. JIT is still misbehaving so I would recommend avoiding using it while developing. - At this point Tailwind doesn’t get fully integrated with SvelteKit. Tailwind styles need to be added to the apps. Add
to@tailwind base; @tailwind components; @tailwind utilities;src/app.css. There’s a fix in progress for it, discussion at issue #42 - At this point Tailwind styles can be used within Svelte but Storybook is still unaware of them. In order to make it aware first import the application styles to
.storybook/preview.cjs:import '../src/app.css'; - Also change
.storybook/main.jsaccording to the following example:const path = require('path'); module.exports = { stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx|svelte)'], addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-svelte-csf'], svelteOptions: { // "preprocess": require("../svelte.config.js").preprocess }, webpackFinal: async (config) => { // Remove the existing css rule config.module.rules = config.module.rules.filter((f) => f.test.toString() !== '/\\.css$/'); config.module.rules.push({ rules: [ { test: /\.css$/i, use: ['style-loader', 'css-loader', 'postcss-loader'] } ], include: path.resolve(__dirname, '../src') }); return config; } };
Issue Analytics
- State:
- Created 2 years ago
- Reactions:17
- Comments:7 (2 by maintainers)

Top Related StackOverflow Question
@sveltejs/kit/experimental/vitehas been released in@sveltejs/kitversion1.0.0-next.353in part to provide improved Storybook support. Feedback welcome in https://github.com/sveltejs/kit/issues/5184Just FYI Sveltekit runtime modules are fixed if you use the Vite storybook builder, they won’t work with webpack