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

stylus-inline-webpack

v1.0.0

Published

Stylus plugin for inlining images

Downloads

3

Readme

Missing Stylus Plugin for Inlined Images

1. Why inline images

It's usefull for cases with big amount of small pictures existing on a web page. When they are inlined in CSS file, there is no unnecessary network connections. Inlining is very common case for SVG handling, because there is no such thing as "SVG sprite".

2. Why inline SVG in encoded format

Stylus has inlining feature (https://learnboost.github.io/stylus/docs/functions.url.html). Unfortunately, it use base64 encoding only. Just two words: it's redundant. SVG should be encoded in URL format. Please read more on http://codepen.io/Tigt/post/optimizing-svgs-in-data-uris.

3. Why use Stylus plugin instead of Postcss

You could use Postcss plugins in order to inline SVG (check out https://github.com/Pavliko/postcss-svg). But there is a small inconvenience here. In fact, you wouldn't use standart url() syntax, but svg() instead, for svg backgrounds. This module offer you use url() or inline-image() or something else you like, for all types of inlined images. Also, I truly believe, there is no sense to include such things like svg() into CSS standart (W3C), so we shouldn't polyfill it through Postcss.

4. Why use Stylus plugin instead of Webpack loaders

Forst of all, there is Stylus loader for Webpack https://github.com/shama/stylus-loader. In Webpack we have standart loader that are dealing with images inlining (https://github.com/webpack/url-loader). So far we have even SVG webpack loader https://github.com/bhovhannes/svg-url-loader. But it will change all the files turning it into inline ones. We could set files weight as a constraint, but I prefer agile universal solutions, when a developer has a chance to decide about inlining by himself.

Webpack Config Example

  module: {
    loaders: [ {
      name: 'styl',
      test: /\.styl$/,
      include: __dirname + '/builds/',
      loader: ExtractTextPlugin.extract(
        'style-loader',
        'css-loader!postcss-loader!stylus-loader'),
    }, {
      name: 'pics',
      test: /\.(jpeg|png|svg)$/,
      include: __dirname + '/builds/',
      loaders: [ 'file?name=[name].[ext]' ],
    } ]
  },
  stylus: {
    define: {
      'inline-image': require('stylus-inline-webpack')({
        limit: 50000
      })
    }
  },

Known Issues

  • There is no automatic rebuild in Webpack when developer changes background image source. Just don't use inline syntax in development, set it at the end of work.