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

wc-sass-render

v1.4.0

Published

Render Sass into importable templates for Typescript or Javascript

Downloads

1,943

Readme

Web Component SASS Render

npm Travis Codecov

Compile Sass files to a lit-html style template to be imported by JS like lit-element .

Motivation

This project was written by inspired by Google's Material Web Component Sass Render. I expanded this out to be non Material specific, and include libraries and recursive directory parsing.

This project exists to make your SASS modular, and importable by any style of Web Components you want to use.

Installation

yarn global add wc-sass-render This will install sass-render as a global CLI tool.

Usage & options

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

Simple usage Renders a ./src/components/button-css.js file

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

Compile directory Renders all scss files in recursively in directory with a custom template

sass-render ./src/**/*.scss -t css-template.js

Compile multiple files or directories Renders all scss files in recursively in directory with a custom template

sass-render ./src/**/*.scss ./lib/component.scss -t css-template.js

Watching Use -w to watch for changes

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

Files will be outputted as [name]-css.js. EG: If file is button.scss, outputted file will be button-css.js.

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

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.js. EG: If file is button.scss, outputted file will be button-css.js. This can be changed with the --suffix option.

NOTE: 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, wc-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 comma separating them.

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

Importing

Once your SASS files are converted into js/ts files, you can use them inside a library like lit-element:

import {html, LitElement} from '@polymer/lit-element';
import CSS from './button-css.js';

export default class Button extends LitElement {
    _render() {
        return html`
            ${CSS}
            <button><slot>Submit</slot></button>
        `;
    }
}
window.customElements.define('my-button', Button);

Custom template

By default, the template is:

import {html} from 'lit-element';
export default html`<style><% content %></style>`;

This can be overridden with the -t option to your own file. EG:

module.exports.CSS = '<% content %>';

Contributions

All pull requests and contributions are most welcome. Let's make the internet better!

Moving forward / TODO

  • [x] Watch command
  • [x] Add tests

Issues

If you find a bug, please file an issue on the issue tracker on GitHub.

Credits

The concept of wc-sass-render was originally created by Google. This project is built and maintained by Tristan Matthias.