Giter VIP home page Giter VIP logo

stylepack's Introduction

Stylepack

Life-changing CSS workflow, leveraging the magic of Stylus, Webpack, and CSS Modules. Stylepack gives you:

  • CSS with all the features of Stylus
  • Proper style isolation using CSS Modules (optional)
  • Shared variables between your JavaScript and styles
  • Support for webpack's awesome Hot Module Replacement for development mode

Install

npm install --save stylepack stylus

Usage

Simple example:

// webpack.config.js

const webpackConfig = {
    // ... your existing webpack configuration ...
};

// Pass the webpack config object through this function to add
// stylus & CSS module goodness to your webpack setup:
const applyStylepack = require('stylepack')({
    webpack: require('webpack'),
    // optional stylepack config goes here
})
module.exports = applyStylepack(webpackConfig)

Now, say you have a foo.styl file in your project as follows:

.bar
    color: red
    font-weight: bold

Then in your client-side JS code, you can import this stylus file, and webpack will compile and bundle it automatically. The default import will be a hash of classnames that you can use in your JavaScript (eg. for React components):

import classes from './foo.styl'

document.body.classList.add(classes.bar)

Configuration

The stylepack function takes an optional configuration object, with the following supported keys:

  • cssModules - Set this to true to enable CSS Modules
  • vars - An object containing variables that will be available to the stylus files. This allows you to share variables across your stylesheets and application JavaScript (eg. colours, animation times, media query breakpoints). Note: nested objects and arrays are not yet supported within the vars option
  • fileMatchRegex - A RegExp used to match files that Stylepack will process. (default: /\.styl$/)
  • extractTo - The name of a CSS file to extract the style rules into. Usually you only want to enable this option in production mode

TODO

  • Remove webpack dependency. It's only in the package.json because extract-text-webpack-plugin errors out without it. Ideally you should be able to "bring your own" webpack version, without this plugin also requiring it directly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.