All Projects → stackcss → Sheetify

stackcss / Sheetify

Licence: mit
✨ Modular CSS bundler for browserify

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sheetify

Phaser Node Kit
Rapid Game Development with PhaserJS and Node for Modern Browsers
Stars: ✭ 39 (-91.2%)
Mutual labels:  browserify, bundler
Tinyify
a browserify plugin that runs various optimizations, so you don't have to install them all manually. makes your bundles tiny!
Stars: ✭ 392 (-11.51%)
Mutual labels:  browserify
domain-browser
Node's domain module for the web browser
Stars: ✭ 30 (-93.23%)
Mutual labels:  browserify
Pundle
👾 peaceful bundles - js bundler, built from the ground up for speed and extensibility
Stars: ✭ 354 (-20.09%)
Mutual labels:  bundler
Commonjs Assert
Node.js's require('assert') for all engines
Stars: ✭ 255 (-42.44%)
Mutual labels:  browserify
Trunk
Build, bundle & ship your Rust WASM application to the web.
Stars: ✭ 378 (-14.67%)
Mutual labels:  bundler
Webpack-4-boilerplate
🚀 Webpack 4 with ES6+ and SASS,LESS/STYLUS support + dev-server and livereload
Stars: ✭ 55 (-87.58%)
Mutual labels:  bundler
Fuse Box
A blazing fast js bundler/loader with a comprehensive API 🔥
Stars: ✭ 4,055 (+815.35%)
Mutual labels:  bundler
Browserify Middleware
express middleware for browserify, done right
Stars: ✭ 385 (-13.09%)
Mutual labels:  browserify
Mochify.js
☕️ TDD with Browserify, Mocha, Headless Chrome and WebDriver
Stars: ✭ 338 (-23.7%)
Mutual labels:  browserify
Wp Webpack Script
💥🔥📦👩‍💻 An easy to use, pre configured, hackable webpack setup & development server for WordPress themes and plugins.
Stars: ✭ 314 (-29.12%)
Mutual labels:  bundler
Eustia
Tool for generating utility libraries
Stars: ✭ 276 (-37.7%)
Mutual labels:  bundler
Gulp Tutorial
Code examples for my Gulp.js tutorial series
Stars: ✭ 383 (-13.54%)
Mutual labels:  browserify
generator-phaser-browserify
A generator for Phaser using Gulp and Browserify
Stars: ✭ 36 (-91.87%)
Mutual labels:  browserify
Metro
🚇 The JavaScript bundler for React Native.
Stars: ✭ 4,308 (+872.46%)
Mutual labels:  bundler
circleci-ruby-orbs
CircleCI orb for ruby
Stars: ✭ 16 (-96.39%)
Mutual labels:  bundler
Svelvet
🧵 An experimental svelte compiler & watcher that works with snowpack
Stars: ✭ 310 (-30.02%)
Mutual labels:  bundler
Simple Get
Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines
Stars: ✭ 357 (-19.41%)
Mutual labels:  browserify
Bitcoinjs Lib
A javascript Bitcoin library for node.js and browsers.
Stars: ✭ 4,418 (+897.29%)
Mutual labels:  browserify
Debundle
🗃 A javascript debundler. Takes a Browserify or Webpack bundle and recreates the initial, pre-bundled source.
Stars: ✭ 420 (-5.19%)
Mutual labels:  browserify

sheetify

NPM version build status Test coverage Downloads js-standard-style

Modular CSS bundler for browserify. Works with npm modules like browserify does.

Features

  • clarity: namespace CSS, no more need for naming schemes
  • modularity: import and reuse CSS packages from npm
  • extensibility: transform CSS using existing transforms, or write your own
  • transparency: inline CSS in your views
  • simplicity: tiny API surface and a minimal code base

Example

Given some inline CSS:

const css = require('sheetify')
const html = require('nanohtml')

const prefix = css`
  :host > h1 {
    text-align: center;
  }
`

const tree = html`
  <section class=${prefix}>
    <h1>My beautiful, centered title</h1>
  </section>
`

document.body.appendChild(tree)

Compile with browserify using -t sheetify:

$ browserify -t sheetify index.js > bundle.js

CSS classes are namespaced based on the content hash:

._60ed23ec9f > h1 {
  text-align: center;
}

And the rendered HTML includes the namespace:

<section class="_60ed23ec9f">
  <h1>My beautiful, centered title</h1>
</section>

Styling host elements

The element that gets a prefix applied can be styled using the :host pseudoselector:

const css = require('sheetify')
const html = require('nanohtml')

const prefix = css`
  :host {
    background-color: blue;
  }

  :host > h1 {
    text-decoration: underline;
  }
`

const tree = html`
  <section class=${prefix}>
    <h1>My beautiful, centered title</h1>
  </section>
`

document.body.appendChild(tree)

By using :host we are able to provide styles for the parent element:

._60ed23ec9f {
  background-color: blue;
}

._60ed23ec9f > h1 {
  text-decoration: underline;
}
<section class="_60ed23ec9f">
  <h1>My beautiful, centered title</h1>
</style>

Dynamic vs static

Sheetify is very good for namespacing static css assets in your javaScript code. Currently there is no support for dynamic variables within sheetify, however you could achieve this by setting the inline style property of an element.

const css = require('sheetify')
const html = require('nanohtml')

const sectionWidth = '100px';
const prefix = css`
  :host {
    background-color: blue;
  }

  :host > h1 {
    text-decoration: underline;
  }
`

const tree = html`
  <section class=${prefix} style="width:${sectionWidth}">
    <h1>My beautiful, centered title</h1>
  </section>
`

document.body.appendChild(tree)

Should you want to, you could even set dynamic variables in an object and do a rather complicated JSON.stringify with a replace on that object to turn it into a style for an element.

const dynamicStyles = {
  width: global.window.innerWidth,
  height: global.window.innerHeight,
}

let dynamicStyleString = JSON.stringify(dynamicStyles)
    .replace(/\,/g,';')
    .replace(/\"/g,'')
    .replace(/\{|\}/g,'')

const tree = html`
  <div style="${dynamicStyleString}">
    <h1>My beautiful, window width</h1>
  </div>
`

External files

To include an external CSS file you can pass a path to sheetify as sheetify('./my-file.css'):

const css = require('sheetify')
const html = require('nanohtml')

const prefix = css('./my-styles.css')

const tree = html`
  <section class=${prefix}>
    <h1>My beautiful, centered title</h1>
  </section>
`

document.body.appendChild(tree)

Use npm packages

To consume a package from npm that has .css file in its main or style field:

const css = require('sheetify')

css('normalize.css')

Packages from npm will not be namespaced by default.

Write to separate file on disk

To write the compiled CSS to a separate file, rather than keep it in the bundle use css-extract:

$ browserify index.js \
  -t [ sheetify ] \
  -p [ css-extract -o bundle.css ] index.js \
  -o bundle.js

css-extract can also write to a stream from the JS api, look at the documentation to see how.

Transforms

Sheetify uses transforms that take CSS and apply a transform. For example include sheetify-cssnext to support autoprefixing, variables and more:

const css = require('sheetify')
const html = require('nanohtml')

const prefix = css`
  h1 {
    transform: translate(0, 0);
  }
`

const tree = html`
  <section class=${prefix}>
    <h1>My beautiful, centered title</h1>
  </section>
`

document.body.appendChild(tree)

Compile with browserify using -t [ sheetify -t sheetify-cssnext ]:

$ browserify -t [ sheetify -t sheetify-cssnext ] index.js > bundle.js

Transforms the CSS into:

h1 {
  -webkit-transform: translate(0, 0);
          transform: translate(0, 0);
}

API

Browserify transforms accept either flags from the command line using subargs:

$ browserify -t [ sheetify -t sheetify-cssnext ] index.js > bundle.js

Or the equivalent options by passing in a configuration object in the JavaScript API:

const browserify = require('browserify')

const b = browserify(path.join(__dirname, 'transform/source.js'))
b.transform('sheetify', { transform: [ 'sheetify-cssnext' ] })
b.bundle().pipe(process.stdout)

The following options are available:

Options:
  -t, --transform    Consume a sheetify transform

Installation

$ npm install sheetify

See Also

  • browserify - browser-side require() the node.js way
  • glslify - module system for GLSL shaders
  • hyperx - transform inline HTML to JS
  • bankai - DIY server middleware for JS, CSS and HTML
  • css-extract: extract CSS from a browserify bundle

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].