webpack-loader-css-styled-jsx-component

0.1.0 • Public • Published

webpack-loader-css-styled-jsx-component

Webpack loader for transpiling css files into styled-jsx component.

Reasoning

We want to use styled-jsx as a method of delivery stylesheets to documnet

Advantages:

  • 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.

We want to take advantage of css pre-processing

SASS or LESS awesomeness

We want to inject themes into css

We use BEM methodology

All styles are applied by class names. Therefore, we have no need for scoping styles.

Installation

npm i -D webpack-loader-css-styled-jsx-component

Peer Dependencies

Usage

Component.jsx

import Styles from './Component.scss'
const theme = {
  primaryColor: '#ff0000'
}

export default Component = () => (
  <div className='component'>
    <Styles theme={theme}/>
  </div>
)

Component.scss

.component {
  color: -var(--theme-primaryColor);
}

webpack.config.js

const path = require('path')

module.exports = {
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              babelrc: false,
              extends: path.resolve(__dirname, './.babelrc')
            }
          },
          'webpack-loader-css-styled-jsx-component',
          'sass-loader'
        ]
      }
    ]
  }
}

.babelrc

{
  "presets": [
    "env",
    "react"
  ],
  "plugins": [
    "styled-jsx/babel"
  ]
}

Notes

Dependents (0)

Package Sidebar

Install

npm i webpack-loader-css-styled-jsx-component

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

5.65 kB

Total Files

5

Last publish

Collaborators

  • antonrublev