Sheetify CSS Bundler

8.0.0 · active · verified Tue Apr 21

Sheetify is a modular CSS bundler designed primarily for use with Browserify. It allows developers to import and namespace CSS directly within JavaScript files, treating CSS as a first-class module similar to how JavaScript modules are handled via npm. The current stable version is 8.0.0. While not following a strict frequent release cadence, it receives updates for dependency maintenance and feature enhancements. Key differentiators include its ability to automatically namespace CSS classes based on content hashes, eliminating the need for complex BEM-like naming schemes, and its extensibility through transforms. It enables importing CSS packages from npm, inlining CSS directly into views for transparency, and offers a minimal API surface. It specifically targets client-side bundling workflows where Browserify is the primary tool for module resolution and bundling.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `sheetify` with Browserify to namespace inline CSS defined using tagged template literals and append the resulting HTML to the document body, including setup instructions.

const css = require('sheetify');
const html = require('nanohtml'); // Example: nanohtml is a common pairing for DOM manipulation

// Define inline CSS using sheetify's tagged template literal
const prefix = css`
  :host {
    background-color: #f0f0f0;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }
  :host > h1 {
    text-align: center;
    color: #333;
    font-family: sans-serif;
  }
  :host > p {
    color: #666;
    text-align: justify;
  }
`;

// Create HTML using nanohtml, applying the namespaced CSS class
const tree = html`
  <section class=${prefix}>
    <h1>My Modular Section</h1>
    <p>This paragraph demonstrates how Sheetify namespaces CSS rules to prevent global style conflicts. The styles defined above are scoped to this section element.</p>
  </section>
`;

// Append the generated HTML to the document body
document.body.appendChild(tree);

// To run this example:
// 1. Install dependencies: npm install sheetify nanohtml browserify
// 2. Save the code above as `index.js`.
// 3. Run the Browserify command: browserify -t sheetify index.js -o bundle.js
// 4. Create an `index.html` file with: <script src="bundle.js"></script> and open in browser.

view raw JSON →