A Boilerplate for building react components using typescript and storybook
Technologies:
- Storybook
- Typescript
- Vitest ⚡
- React
- SCSS (for Sass look here)
- postCSS
- husky 🐶 + lint-staged
- eslint + prettier
Features:
- Zero storybook-production mismatch
- Unit Tests (using
vitest
) - Full control over each configuration
- CSS Preprocessors support + Autoprefixer support
- CSS Modules support
to get the boilerplate type the following:
npx degit https://github.com/MatanelGordon/react-component-boilerplate.git <directory name>
to get the boilerplate type the following:
git clone --depth 0 https://github.com/MatanelGordon/react-component-boilerplate.git <directory name>
To run storybook, type the following:
npm run storybook
NOTE: You can also use yarn / pnpm
to build your project, type the following:
npm run build
There are several different ways to run tests:
npm run test
- will run all testsnpm run test:dev
- will run all tests when a file changesnpm run test:ui
- will open a webview with all the tests and run them on change
NOTE: You can also use yarn / pnpm
install the boilerplate inside packages/
refer to Usage
install the boilerplate inside packages/
refer to Usage
In order to add more rules - Modify webpack.config.js
file, from there, it will sync all rules with storybook and allow you to enjoy it both in dev and production.
Also, there might be cases where you need to change other configurations such as eslint, postcss and stylelint
By default, this boilerplate uses SCSS
. To use Sass
, do the following:
- uninstall
postcss-scss
and installpostcss-sass
- change in
postcss.config.js
:
const autoPrefixer = require('autoprefixer');
module.exports = {
syntax: 'postcss-sass',
plugins: [
autoPrefixer
]
}
- (optional) If stylelint throws errors, be sure to uninstall
stylelint-config-standard-scss
First, uninstall sass
, sass-loader
, and postcss-scss
.
npm un sass sass-loader postcss-scss
then, install less
, less-loader
and postcss-less
npm i -D less less-loader postcss-less
Then, modify css rule in webpack.config.js
file to be the following:
{
test: /\.less$/,
use: [
'style-loader',
{
loader: "css-loader",
options: {
modules: {
auto: true
}
}
},
{
loader: 'postcss-loader',
options: {
implementation: require('postcss'),
},
},
{
loader: "less-loader",
options: {
implementation: require("less"),
},
},
]
}
Then, uninstall stylelint-config-standard-scss
and install stylelint-config-recommended-less
.
npm un stylelint-config-standard-scss
to install stylelint-config-recommended-less
:
npm i -D stylelint-config-recommended-less
Don't forget to change to
stylelint-config-recommended-less
instylelint.config.js
file