[![Netlify Status](https://api.netlify.com/api/v1/badges/b4aa4a04-e097-4067-87ec-9a6681335673/deploy-status)](https://app.netlify.com/sites/svelte-tailwindcss-storybook/deploys) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjerriclynsjohn%2Fsvelte-storybook-tailwind.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjerriclynsjohn%2Fsvelte-storybook-tailwind?ref=badge_shield)
# A starter template for Svelte, TailwindCSS and Storybook
![Svelte + TailwindCSS + Storybook Starter Template](starter-template.jpg)
> Visit this website to see the outcome: [Svelte + TailwindCSS + Storybook](https://svelte-tailwindcss-storybook.netlify.com)
```bash
// Quickstart
npx degit jerriclynsjohn/svelte-storybook-tailwind my-svelte-project
cd my-svelte-project
yarn
yarn dev
yarn stories
```
Svelte and TailwindCSS is an awesome combination for Frontend development, but sometimes the setup seems a bit non intuitive, especially when trying to try out this awesome combination. When integrating Storybook, which is another awesome tool for UI Component development and documentation, there is no obvious place to get how it's done. This repo was made to address just that!
> You can easily start your project with this template, instead of wasting time figuring out configurations for each integration.
## What do you get in this repo
![Storybook UI](Storybook-alert-modern.PNG)
1. A fully functional Svelte + TailwindCSS integration with side-by-side implementation of independent Storybook
2. Storybook with 5 essential Addons
3. Storybook populated with basic examples of Svelte + TailwindCSS
### Addons
- Accessibility Addon
![Accessibility Addon](storybook-accessibility-addon.PNG)
- Accessibility Addon - Colorblindness Emulation
![Accessibility Addon - Colorblindness Emulation](storybook-accessibility-addon-colorblindness-emulation.PNG)
- Actions Addon
![Actions Addon](storybook-actions-addon.PNG)
- Notes Addon
![Notes Addon](storybook-Documentation-Component.PNG)
- Source Addon
![Source Addon](storybook-storycode-addon.PNG)
- Viewport Addon
![Source Addon](storybook-viewport-addon.PNG)
## Svelte + TailwindCSS + Storybook
[Storybook](https://storybook.js.org/) is an open source tool for developing JavaScript UI
components in isolation
[Svelte](https://svelte.dev/) is a component framework that allows you to write highly-efficient,
imperative code, that surgically updates the DOM to maintain performance.
[TailwindCSS](https://tailwindcss.com) is a highly customizable, low-level CSS framework that gives
you all of the building blocks you need to build bespoke designs without any annoying opinionated
styles you have to fight to override.
## Steps to build
1. Clone this repo `git clone https://github.com/jerriclynsjohn/svelte-storybook-tailwind.git`
2. Go to the directory `cd svelte-storybook-tailwind`
3. Install dependencies `yarn`
4. To develop your Svelte App: `yarn dev`
5. To develop UI components independent of your app: `yarn stories`
### Documentations
1. Svelte - [API](https://svelte.dev/docs) and [Tutorial](https://svelte.dev/tutorial/)
2. TailwindCSS - [Docs](https://tailwindcss.com/docs) and [Tutorial](https://tailwindcss.com/screencasts/)
3. Storybook - [Docs](https://storybook.js.org/docs/basics/introduction/) and [Tutorial](https://www.learnstorybook.com/intro-to-storybook/svelte/en/get-started/)
## Steps to build it all by yourself and some tips [Warning: It's lengthy]
### Instantiate Svelte App
- Start the template file using `npx degit sveltejs/template svelte-storybook-tailwind`
- Go to the directory `cd svelte-storybook-tailwind`
- Install dependencies `yarn`
- Try run the svelte app `yarn dev`
### Add Tailwind into the project
- Install dependencies:
`yarn add -D tailwindcss @fullhuman/postcss-purgecss autoprefixer postcss postcss-import svelte-preprocess`
- Change the rollup config as shown:
```javascript
import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import autoPreprocess from 'svelte-preprocess';
const production = !process.env.ROLLUP_WATCH;
export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/bundle.js',
},
plugins: [
svelte({
preprocess: autoPreprocess({
postcss: true,
}),
// enable run-time checks when not in production
dev: !production,
// we'll extract any component CSS out into
// a separate file — better for performance
css: css => {
css.write('public/bundle.css');
},
}),
postcss({
extract: 'public/utils.css',
}),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration —
// consult the documentation for details:
// https://github.com/rollup/rollup-plugin-commonjs
resolve({
browser: true,
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/'),
}),
commonjs(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser(),
],
watch: {
clearScreen: false,
},
};
```
- Add tailwind config using the command `npx tailwind init`
- Add PostCSS config `./postcss.config.js` as follows:
```javascript
const production = !process.env.ROLLUP_WATCH;
const purgecss = require('@fullhuman/postcss-purgecss');
module.exports = {
plugins: [
require('postcss-import')(),
require('tailwindcss'),
require('autoprefixer'),
production &&
purgecss({
content: ['./**/*.html', './**/*.svelte'],
defaultExtractor: content => {
const regExp = new RegExp(/[A-Za-z0-9-_:/]+/g);
const matchedTokens = [];
let match = regExp.exec(content);
// To make sure that you do not lose any tailwind classes used in class directive.
// https://github.com/tailwindcss/discuss/issues/254#issuecomment-517918397
while (match) {
if (match[0].startsWith('class:')) {
matchedTokens.push(match[0].substring(6));
} else {
matchedTokens.push(match[0]);
}
match = regExp.exec(content);
}
return matchedTokens;
},
}),
],
};
```
- Build the project with some TailwindCSS utilities `yarn dev`
### Add Storybook into the Svelte Project
- Add Storybook dependencies `yarn add -D @storybook/svelte`
- Add 5 commonly used Storybook [Addons](https://storybook.js.org/addons/):
- [Source](https://github.com/storybookjs/storybook/tree/master/addons/storysource):
`yarn add -D @storybook/addon-storysource`
- [Actions](https://github.com/storybookjs/storybook/tree/master/addons/actions):
`yarn add -D @storybook/addon-actions`
- [Notes](https://github.com/storybookjs/storybook/tree/master/addons/notes):
`yarn add -D @storybook/addon-notes`
- [Viewport](https://github.com/storybookjs/storybook/tree/master/addons/viewport):
`yarn add -D @storybook/addon-viewport`
- [Accessibility](https://github.com/storybookjs/storybook/tree/master/addons/a11y):
没有合适的资源?快使用搜索试试~ 我知道了~
svelte-storybook-tailwind:Svelte,TailwindCSS和Storybook的入门模板。 您可以...
共73个文件
svelte:22个
js:19个
png:9个
需积分: 14 2 下载量 107 浏览量
2021-02-03
13:50:08
上传
评论
收藏 1.43MB ZIP 举报
温馨提示
Svelte,TailwindCSS和Storybook的入门模板 访问此网站以查看结果: // Quickstart npx degit jerriclynsjohn/svelte-storybook-tailwind my-svelte-project cd my-svelte-project yarn yarn dev yarn stories Svelte和TailwindCSS对于Frontend开发来说是一个很棒的组合,但是有时设置似乎有点不直观,特别是在尝试尝试这个很棒的组合时。 集成Storybook(这是用于UI组件开发和文档的另一个很棒的工具)时,没有明显的地方可以了解它的完成方式。 这个仓库就是为了解决这个问题! 您可以使用此模板轻松启动项目,而不是浪费时间为每个集成确定配置。 你在这个仓库里得到什么 功能齐全的Svelte + TailwindCSS集成与独立Storybook的并行实现 具有5个基本附件的故事书 故事书中填充了Svelte + TailwindCSS的基本示例 插件 辅助功能附件 辅助功能附加组件-色盲仿真 动作插件 笔记插件
资源详情
资源评论
资源推荐
收起资源包目录
svelte-storybook-tailwind-master.zip (73个子文件)
svelte-storybook-tailwind-master
storybook-viewport-addon.PNG 30KB
starter-template.jpg 70KB
.eslintrc 222B
rollup.config.js 2KB
.github
workflows
nodejs.yml 509B
postcss.config.js 1KB
public
index.html 371B
favicon.png 3KB
storybook-ui.PNG 41KB
storybook-actions-addon.PNG 6KB
tailwind.config.js 97B
.prettierignore 237B
src
main.js 129B
utils.css 133B
components
Button.svelte 394B
nav.svelte 2KB
App.svelte 308B
.storybook
postcss.config.js 202B
webpack.config.js 1KB
config.js 453B
addons.js 219B
CONTRIBUTING.md 2KB
LICENSE 1KB
storybook
stories
alerts
alerts.stories.js 3KB
alerts.stories.md 755B
buttons
buttons.stories.md 742B
buttons.stories.js 3KB
forms
forms.stories.md 756B
forms.stories.js 2KB
components
alerts
AlertLeftAccent.svelte 257B
AlertSolid.svelte 859B
AlertTitled.svelte 364B
AlertTopAccentBorder.svelte 838B
AlertModern.svelte 678B
AlertTraditional.svelte 923B
AlertBanner.svelte 280B
buttons
ButtonGroups.svelte 393B
Button3D.svelte 210B
ButtonDisabled.svelte 173B
ButtonIcon.svelte 399B
ButtonBordered.svelte 184B
ButtonSimple.svelte 363B
ButtonElevated.svelte 195B
ButtonOutline.svelte 395B
ButtonPill.svelte 155B
forms
FormsPassword.svelte 638B
FormsCustomSelect.svelte 842B
FormsError.svelte 658B
css
utils.css 136B
README.md 13KB
.out
main.6190f66ff1e19d5f17ed.bundle.js 994KB
vendors~main.6190f66ff1e19d5f17ed.bundle.js 1.27MB
runtime~main.6190f66ff1e19d5f17ed.bundle.js.map 169B
index.html 1KB
runtime~main.6190f66ff1e19d5f17ed.bundle.js 3KB
sb_dll
storybook_ui_dll.js 1.14MB
storybook_ui_dll.LICENCE 3KB
storybook_ui-manifest.json 79KB
favicon.ico 32KB
main.7fe2dfa41a28af335bb2.bundle.js 214B
main.6190f66ff1e19d5f17ed.bundle.js.map 153B
vendors~main.6190f66ff1e19d5f17ed.bundle.js.map 325B
vendors~main.82a5df8d81e99382f448.bundle.js 1.33MB
iframe.html 3KB
runtime~main.3e80324d580cf3681712.bundle.js 1KB
storybook-accessibility-addon.PNG 12KB
prettier.config.js 687B
storybook-accessibility-addon-colorblindness-emulation.PNG 23KB
Storybook-alert-modern.PNG 45KB
.gitignore 857B
storybook-Documentation-Component.PNG 15KB
storybook-storycode-addon.PNG 19KB
package.json 2KB
共 73 条
- 1
Tstormatroc
- 粉丝: 28
- 资源: 4526
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0