rollup-plugin-sass-styled-jsx-component
Rollup plugin for transpiling sass files into styled-jsx component
Reasoning
styled-jsx as a method of delivery stylesheets to documnet
We want to useAdvantages:
- Claims to be blazingly fast
- Supports dynamic styles -> themability
- Only loads css used by the components on the page
- Does not repeat css for resusable components
- Cleans up after itself
- Plays well with isomorphic app
Disadvantages:
- no stylesheet bundles -> stylesheets are not cached (however, js bundles that include css can still be cached)
We do not want to write css in string literals in javascript files
Onle language per file. Syntax highlighting.
SASS pre-processing
We want to take advantage ofWe want to inject themes into css
BEM methodology
We useAll styles are applied by class names. Therefore, we have no need for scoping styles.
Installation
npm i -D rollup-plugin-sass-styled-jsx-component
Peer Dependencies
Usage
Component.jsx
const theme = primaryColor: '#ff0000' = <div className='component'> <Styles theme=theme/> </div>
Component.scss
.component
rollup.config.js
input: 'src/index.js' plugins: output: file: 'dist/lib/index.js' format: 'cjs' exports: 'named' file: 'dist/es/index.js' format: 'es' exports: 'named' Object || /^styled-jsx/
With extra css processing
rollup.config.js
const processor = ` div { color: red; }` input: 'src/index.js' plugins: output: file: 'dist/lib/index.js' format: 'cjs' exports: 'named' file: 'dist/es/index.js' format: 'es' exports: 'named' Object || /^styled-jsx/
Custom include pattern
Default patterns: [ '**/*.sass', '**/*.scss' ]
rollup.config.js
Custom exclude pattern
Default patterns: none
Note: Another sass pluging must process excluded resources. Otherwise, rollup will fail.
rollup.config.js
node-sass options
rollup.config.js
Notes
- We also use webpack for storybook dev environment for ui components - https://github.com/360incentives/webpack-loader-css-styled-jsx-component