Socket
Socket
Sign inDemoInstall

jss-sheet-loader

Package Overview
Dependencies
128
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jss-sheet-loader

Create and load jss with no pain


Version published
Maintainers
1
Install size
6.87 MB
Created

Readme

Source

JSS Loader for Webpack

Create and load jss with no pain

Install it

npm i jss-sheet-loader --save

Use it

JSS file (you can use .jss extension and make your editor/IDE handle it like .js):

import myColors from 'path/to/my/colors.js';

export default {
  myElement: {
    color: myColors.orange,
    margin: 10
  }
}

JS file:

import styles from 'path/to/jss/file.jss';

// ...

<div className={styles.myElement}>Some content</div>

Webpack config file:

{
  //...
  module   : {
    rules: [ {
      test   : /\.jss$/,
      exclude: /node_modules/,
      use    : [ {
        loader : 'jss-sheet-loader',
        options: {
          plugins: [
            // List here the plugins you wanna use
            // Don't forget to install them!
            'jss-nested'
          ]
        }
      } ]
    } ]
  }
}

Keywords injection

Combined with jss-expand and jss-default-unit plugin, you can use the following syntax:

const borderWidth = 2;

export default {
  myElement: {
    border    : [borderWidth, solid, black],
    display   : flex,
    flexAlign : flexEnd
  }
}

Instead of

const borderWidth = 2;

export default {
  myElement: {
    border    : `${borderWidth}px solid black`,
    display   : 'flex',
    flexAlign : 'flex-end'
  }
}

And you don't need to declare var solid = "solid" or any other css keyword, just set loader option injectKeywords to true and the magic is done:

{
  //...
  {
    // ...
    use    : [ {
      loader : 'jss-sheet-loader',
      options: {
        injectKeywords: true,
        plugins: [
          // ...
        ]
      }
    } ]
  }
}

FAQs

Last updated on 21 Apr 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc