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

yoink-css

v0.3.1

Published

Extract and scope CSS in template files

Downloads

7

Readme

Yoink

Yoink allows you to take a CSS-in-JS-like approach to writing CSS inside template files of other languages and non-js specific projects.

Features

  • Co-locate CSS code with the template markup it corresponds to.
  • Scope classes to the markup in that file.
  • Write SCSS, LESS or any other CSS preprocessor syntax.
  • Extracts CSS to a single file that can then be used as part of your usual build process.
  • Can be used with both Gulp and NPM scripts / CLI.

Caveats

  • This project is currently a work in progress and whilst currently used in production projects, it has only been tested with a limited amount of template languages / project setups.
  • Unlike most CSS-in-JS approaches, there is no interoperability between the CSS and markup, meaning that, for instance, conditional output of styles is not possible.
  • Writing CSS in template files is not going to be ideal for all projects and is definitely more suited to codebases where templates are made up of small partials, much in the same way React or Vue projects are.
  • It may take a bit of configuration in your text editor to provide proper syntax highlighting when writing CSS in template files.

Motivation

Having enjoyed the dev experience of styling React components and working with CSS-in-JS, this is started an attempt to port/emulate some of that experience across to PHP projects that were using Twig.

Installation

npm install yoink-css

Usage

Yoink removes any internal CSS from templates that have the attribute 'extract'.

<style extract>
    /*...Your CSS here...*/
</style>

Additionally, Yoink will scope any class selector that starts with a particular prefix to the markup in that file. The default prefix is '--' although this can be changed in the configuration.

.--your_class {
     /*...Your CSS here...*/
}

/* Becomes...*/

._134567_your_class {
     /*...Your CSS here...*/
}

Regular class names and scoped class names can be mix and matched.

.normal_class .--scoped_class  {
     /*...Your CSS here...*/
}

Configuration

If you're using Gulp, Yoink accepts a configuration object with these keys:

css_dest - Required The complete destination path of the merged CSS file (including file name).

Prefix - Default: '--' The class selector prefix that will be replaced to scope a class to it's file.


Using NPM scripts / CLI, an additional 3 args are required:

src - Required The src template folder that gets processed.

dest - Required The destination folder where the processed templates should go.

watch - Default: false Whether to continuously watch the src folder for changes.

NOTE: Currently Yoink requires that both the src and dest folders are NOT your root directory


These args can be passed to Yoink CLI version either using these flags:

--src

--dest

--css_dest

--watch

--prefix


Or alternatively, Yoink will look for a configuration file in your working directory called 'yoink.config.js' that should contain a config object like this:

module.exports = {
    src : './templates/',
    dest: './dist/',
    css_dest: './scss/styles.scss',
    prefix : '--',
    watch : true
}

Examples

As part of a Gulpfile, Yoink will look something like this:

function extract_css() {
    return gulp
        .src(["./templates/**/*"])
        .pipe(yoink({
            css_dest: '.scss/style.scss',
            prefix : '--'
        }))
        .pipe(gulp.dest("./dist/templates/"));
}

Using NPM scripts...

// ...
"scripts": {
      "start": "yoink --src ./src/templates --dest ./dist/ --css_dest ./dest/css --watch"
},
// ...

The examples folder contains a simple working example of both Gulp / NPM scripts usage - run npm install from in each folder to grab the necessary dependencies then either gulp or npm start depending on example.