Plugin framework for CSS preprocessing in Node.js

Related tags

CSS Parsers rework
Overview

rework Build Status

CSS manipulations built on css, allowing you to automate vendor prefixing, create your own properties, inline images, anything you can imagine!

Please refer to css for AST documentation and to report parser/stringifier issues.

Installation

$ npm install rework

Usage

var rework = require('rework');
var pluginA = require('pluginA');
var pluginB = require('pluginB');

rework('body { font-size: 12px; }', { source: 'source.css' })
  .use(pluginA)
  .use(pluginB)
  .toString({ sourcemap: true })

API

rework(code, [options])

Accepts a CSS string and returns a new Rework instance. The options are passed directly to css.parse.

Rework#use(fn)

Use the given plugin fn. A rework "plugin" is simply a function accepting the stylesheet root node and the Rework instance.

Rework#toString([options])

Returns the string representation of the manipulated CSS. The options are passed directly to css.stringify.

Unlike css.stringify, if you pass sourcemap: true a string will still be returned, with the source map inlined. Also use sourcemapAsObject: true if you want the css.stringify return value.

Plugins

Rework has a rich collection of plugins and mixins. Browse all the Rework plugins available on npm.

Plugins of particular note:

  • at2x – serve high resolution images
  • calc – resolve simple calc() expressions
  • colors – color helpers like rgba(#fc0, .5)
  • ease – several additional easing functions
  • extendextend: selector support
  • function – user-defined CSS functions
  • import – read and inline CSS via @import
  • inline – inline assets as data URIs
  • mixin – custom property logic with mixins
  • npm - inline CSS via @import using node's module resolver
  • references – property references like height: @width
  • url – rewrite url()s with a given function
  • variables – W3C-style variables

Built with rework

License

(The MIT License)

Copyright (c) 2012–2013 TJ Holowaychuk [email protected]

Copyright (c) 2014 Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Source Map support

    Source Map support

    It is very important, because a lot of users will use source maps from Sass/Stylus. And if Rework will destroy this map data, if will be bad feature :(.

    sauce-map 
    opened by ai 47
  • Made at2x require a hi-res tag in the value to activate

    Made at2x require a hi-res tag in the value to activate

    As Discussed in Styl #21, I updated the at2x plugin to require hi-res in the value to activate. This lets authors be more selective on its use, and makes sure that people are consciously accepting the consequences of using the plugin on specific images.

    Please let me know if you want anything else tweaked.

    opened by rschmukler 23
  • prefix selectors

    prefix selectors

    I will be happy to implement this if you want, just need some pointers

    this

    ::placeholder {
      color: #aaa
    }
    

    should eql

    ::-webkit-input-placeholder,
    ::-moz-placeholder,
    ::-ms-input-placeholder,
    ::-o-placeholder {
      color: #aaa
    }
    
    high priority 
    opened by yields 21
  • Don't change indentation

    Don't change indentation

    When I proccess

    body {
        transition: all 1s ease-out;
    }
    

    or

    body { transition: all 1s ease-out }
    

    Rework will remove all my formatation and use own styles (without \n at end file):

    body {
      transition: all 1s ease-out
    }
    

    It's not critical, but good postprocessor will change only that, you need.

    pr-plz 
    opened by ai 21
  • remove vendor support from core

    remove vendor support from core

    specifically:

    • Rework#vendors()
    • rework.prefix()
    • rework.prefixValue()
    • rework.keyframes()

    i don't think most people use these and instead use autoprefixer. the only module i've seen that actually uses this is styl, but i think that's only because of @visionmedia's refusal to use anything written in coffee script. these modules won't be deleted, just moved to its own module not included with rework.

    arguments for removal:

    • people use autoprefixer anyways
    • much less maintenance on rework
    • closes #78 #73 #70
    • vendor prefixes are going away in favor of feature flags, so vendor prefix support is short-term thinking
    • manual vendor prefixing is a pain in the ass

    arguments against removal: you tell me

    aye or nay?

    opened by jonathanong 20
  • Placeholder extend leaves empty selector

    Placeholder extend leaves empty selector

    Using placeholder extension leaves an empty selector in the output. An example of this can be seen in the test file: https://github.com/visionmedia/rework/blob/master/test/fixtures/extend.nested.placeholder.out.css

    Expected result seems like it would be either to insert background: black; or to remove the empty selector if the generated extended selectors cover that case in the cascade.

    Steps to reproduce

    1. Create a placeholder selector:

      %dark-button {
          background: black;
      }
      
      .button {
          extend: %dark-button;
      }
      
    2. Run rework use extend

    3. Compare output

    Expected result

    .button {
        background: black;
    }
    

    Actual result

    .button {
        background: black;
    }
    
    .button {
    
    }
    
    opened by kristoferjoseph 17
  • add/error

    add/error

    attempt to address https://github.com/visionmedia/rework/issues/6

    i definitely want to figure out how to solve this problem, because it will make Myth much nicer. open to different ideas though. it could be moved out into a separate helper (although visit is just added in core again so dunno if thats that useful?)

    opened by ianstormtaylor 15
  • Simple variables syntax

    Simple variables syntax

    Variables syntax in CSS is totally mind fucked. We need special :root section, we use different var-NAME in declaration and just var(NAME) in usage.

    If Rework’s vars isn’t spec equalent, maybe we should use normal syntax from Stylus or Sass (I prefer last one, because it is very easy to find variable usage in code and we can’t rewrite systems terms like red = blue).

    opened by ai 15
  • Inline source maps as comments

    Inline source maps as comments

    I propose inlining source maps as a base64 encoded data uris — that would provide excellent dev experience and doesn't require to serve source maps to browser separately.

    sauce-map 
    opened by andreypopp 13
  • Move all plugins to separate libraries.

    Move all plugins to separate libraries.

    I think we should remove all the plugins from core. Follow the same philosophy of node.js itself and make them separate. This would prevent people from opening lots of pull requests asking for core status (e.g. #32 which does this at the moment). We could then create a simple wiki page like we did with component to list them.

    For the command line interface I'd suggest a simple plugin technique where people can list the modules they have installed that supply 'rework' plugins.

    Usage then becomes:

    Usage: rework <plugins> [options]
    
    Options:
    
      -h, --help            output usage information
      -V, --version         output the version number
      -v, --vendors <list>  specify list of vendors
    

    e.g.

    $ rework ease,vars,extend -v webkit,moz < my.css > my.reworked.css
    

    We could have rework automatically attempt require(plugin) and then if that fails it could attempt require('rework-' + plugin)

    This would vastly reduce the size of core and hopefully lead to it being pretty much locked stability once we've sorted how to handle async transformations and syntax transformations.

    opened by ForbesLindesay 13
  • .import(basePath) plugin to read and inline @imported stylesheets

    .import(basePath) plugin to read and inline @imported stylesheets

    Hi,

    Created an @import disk read plugin (#24). It just goes in a depth first search and merges the css ast into current one. Not sure if it's the way you'd want to implement though. Feels kinda ugly.

    opened by eknkc 13
  • Not works if css contains inline comments

    Not works if css contains inline comments

    Not works if css contains inline comments like below. Throwing error

    background: #aaaaaa/{bgColorOverlay}/ url(images/ui-bg_flat_0_aaaaaa_40x100.png)/{bgImgUrlOverlay}/ 50%/{bgOverlayXPos}/ 50%/{bgOverlayYPos}/ repeat-x/{bgOverlayRepeat}/;

    opened by harisjayadev 1
  • nested rules

    nested rules

    rework not supporting nested rules is very limiting. In my case I can't use the css-whitespace parser beforehand because my CSS depends on certain rework plugins to become valid CSS. So css-whitespace fails on it for not understanding the rework pieces and rework fails for not understanding the nesting :( Shouldn't this be an option built into rework?

    opened by geddski 1
  • Async plugins

    Async plugins

    Dupe of #2 but I got an actual API proposition

    What about this

    // sync
    rework(css).use(plugin).toString()
    
    // async; promise-based
    rework(css)
      .then(function(object) {
        return plugin(object);
      })
      .then(function(object) {
        return object.toString();
      })
    
    // or similar
    

    @necolas

    opened by paulmillr 2
Owner
rework
rework
A tool set for CSS including fast detailed parser, walker, generator and lexer based on W3C specs and browser implementations

CSSTree CSSTree is a tool set for CSS: fast detailed parser (CSS → AST), walker (AST traversal), generator (AST → CSS) and lexer (validation and match

CSSTree 1.6k Dec 28, 2022
CSS parser with support of preprocessors

Gonzales PE @dev Gonzales PE is a CSS parser which plays nicely with preprocessors. Currently those are supported: SCSS, Sass, LESS. Try out Gonzales

Tony Ganch 322 Dec 10, 2022
A decent CSS parser.

mensch A decent CSS parser. usage npm install mensch var mensch = require('mensch'); var ast = mensch.parse('p { color: black; }'); var css = mensch.

Brett Stimmerman 112 Sep 24, 2022
Modern CSS to all browsers

stylecow: modern CSS for all browser Node library to fix your css code and make it compatible with all browsers. Created by Óscar Otero. License: MIT

stylecow 155 Dec 21, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Spectre.css - A Lightweight, Responsive and Modern CSS Framework

Spectre.css Spectre.css is a lightweight, responsive and modern CSS framework. Lightweight (~10KB gzipped) starting point for your projects Flexbox-ba

Yan Zhu 11.1k Jan 8, 2023
Framework-agnostic CSS-in-JS with support for server-side rendering, browser prefixing, and minimum CSS generation

Aphrodite Framework-agnostic CSS-in-JS with support for server-side rendering, browser prefixing, and minimum CSS generation. Support for colocating y

Khan Academy 5.3k Jan 1, 2023
Tiny CSS framework with almost no classes and some pure CSS effects

no.css INTERACTIVE DEMO I am tired of adding classes to style my HTML. I just want to include a .css file and I expect it to style the HTML for me. no

null 96 Dec 10, 2022
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.

chai Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework. For more in

Chai.js Assertion Library 7.8k Dec 30, 2022
Reseter.css - A Futuristic CSS Reset / CSS Normalizer

Reseter.css A CSS Reset/Normalizer Reseter.css is an awesome CSS reset for a website. It is a great tool for any web designer. Reseter.css resets all

Krish Dev DB 1.1k Jan 2, 2023
Form To CSS - jQuery-Plugin form to CSS generator

Create your own CSS generator with the form to css generator Builder plugin. Can be usefull to create your own css builder or a Wordpress plugin or any kind of apps you need a real time css generator. For example, you can create a button generator

Gino 4 Sep 26, 2021
Babel-plugin-amd-checker - Module format checking plugin for Babel usable in both Node.js the web browser environments.

babel-plugin-amd-checker A Babel plugin to check the format of your modules when compiling your code using Babel. This plugin allows you to abort the

Ferdinand Prantl 1 Jan 6, 2022
An lldb plugin for Node.js and V8, which enables inspection of JavaScript states for insights into Node.js processes and their core dumps.

Node.js v10.x+ C++ plugin for the LLDB debugger. The llnode plugin adds the ability to inspect JavaScript stack frames, objects, source code and more

Node.js 1k Dec 14, 2022
Node 18's node:test, as a node module

node-core-test This is a user-land port of node:test, the experimental test runner introduced in Node.js 18. This module makes it available in Node.js

Julian Gruber 62 Dec 15, 2022
Dojo Framework. A Progressive Framework for Modern Web Apps

@dojo/framework Dojo is a progressive framework for modern web applications built with TypeScript. Visit us at dojo.io for documentation, tutorials, c

Dojo 549 Dec 25, 2022
The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

Bootstrap Sleek, intuitive, and powerful front-end framework for faster and easier web development. Explore Bootstrap docs » Report bug · Request feat

Bootstrap 161k Jan 1, 2023