npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@noticeable/sass-render

v3.0.0

Published

Render SASS into importable templates for Typescript or Javascript

Downloads

456

Readme

SASS Render

This project makes your SASS modular, and importable by any Web Component libraries you want to use.

By default, this utility compiles SASS files to TypeScript style templates using the lit css tag function. Although this is quite opinionated, you can easily change the output template and the generated file extension.

Installation

You can install sass-render as a dev dependency in your current project:

npm install @noticeable/sass-render --save-dev
yarn add @noticeable/sass-render --dev

or as a global package to have the command sass-render available everywhere:

npm install --global @noticeable/sass-render
yarn global add @noticeable/sass-render

Usage & options

For a list of complete options, run sass-render --help.

Simple usage

Rendering a ./src/components/button-css.ts file:

sass-render ./src/components/button.scss

Compile directory

Rendering all scss files in a directory, recursively:

sass-render ./src/**/*.scss

Compile multiple files or directories

Rendering multiple scss files and directories, recursively:

sass-render ./src/**/*.scss ./lib/component.scss

Watching

Use -w to watch for changes:

sass-render ./src/**/*.scss -w

Files will be outputted as [name]-css.ts.

Custom template

Use -t to specify the file you'd like to use as a template. sass-render will replace <% content %> in the file with the generated output:

sass-render ./src/components/button-css.js -t css-template.js

Expanded CSS

Use -e to enable expanded rendering of output CSS. Render SASS outputs CSS as 'compressed' by default, which may cause parsing errors for some projects.

sass-render ./src/components/button-css.js -t -e css-template.js

Custom suffix

Files will be outputted as [name]-css.ts. If file is button.scss, outputted file will be button-css.ts. This can be changed with the --suffix option.

If you use a - (dash) in your suffix name, eg: --suffix '-css.js', then quotation marks are needed around the suffix (to tell bash it's not another flag).

Import custom libraries

By default, sass-render will include the node_modules relative to the current directory. Passing the -i allows you to include custom directories. You can include multiple directories by separating them with a comma:

sass-render ./src/**/*.scss -i '../sass-lib/'
sass-render ./src/**/*.scss -i '../sass-lib/, ../another-lib'

Importing

Once your SASS files are converted into TypeScript or JavaScript files, you can use them inside a library like lit. Here is a TypeScript example:

import {CSSResult, LitElement, TemplateResult, html} from 'lit';
import {customElement} from 'lit/decorators.js';
import {styles} from './my-button-css.js';

@customElement('my-button')
export class MyButton extends LitElement {

    static get styles(): CSSResult {
        return styles;
    }

    protected render(): TemplateResult {
        return html`<button><slot>Submit</slot></button>`;
    }

}

Credits

This project is inspired by Google's Material Web Component Sass Render. It has been expanded to make the code reusable for other projects and to support recursive directory parsing.

The original code is a fork of https://github.com/tristanMatthias/wc-sass-render/tree/dc4a15718a7e23532807f45bb09e20edfd10cedd.