Socket
Socket
Sign inDemoInstall

css-js-loader

Package Overview
Dependencies
22
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    css-js-loader

Write your styles with in JavsScript.


Version published
Weekly downloads
8
decreased by-33.33%
Maintainers
2
Install size
4.17 MB
Created
Weekly downloads
 

Readme

Source

css-js-loader

Write your styles with in JavsScript.

build status coverage license version downloads

Usage

Install:

npm install css-js-loader value-loader

Add to your webpack.config.js:

module.exports = {
  ...
  module: {
    loaders: [{
      test: /\.css(\.js)?$/,
      loaders: ['style-loader', 'css-loader'],
    }, {
      test: /\.css\.js$/,
      loaders: ['css-js-loader', 'value-loader'],
    }],
  },
};

NOTE: You don't need to chain with value-loader per-se, but doing so gives you caching, nested dependency monitoring/reloading and the ability to use webpack's tree-shaking abilities.

Writing JS Styles

css-js-loader converts JS modules to CSS markup at runtime.

A .css.js file:

export default {
 '.blueText': {
    color: 'blue',
    fontSize: 12,
  },
};

Yields:

.blueText {
  color: blue;
  font-size: 12px;
}

CSS classes can be defined as ES6 named exports.

export const blueText = { ... };

export const greenText = { ... };

export default {
  '.redText': { ... },
};

Is equivalent to:

export default {
  '.blueText': { ... },
  '.greenText': { ... },
  '.redText' { ... },
};

CSS Modules

css-js-loader works great with CSS Modules. Named class exports map directly to the class names that are imported in your component files.

Style file:

export const base = { ... };
export const inner = { ... };

Component file:

import React from 'react';
import {base, inner} from './component.css.js';
export default () =>
  <div className={base}>
    <div className={inner}>
      ...
    </div>
  </div>;

FAQs

Last updated on 06 Nov 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