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

node-lessify

v0.2.0

Published

LESS precompiler and CSS plugin for Browserify

Downloads

1,948

Readme

node-lessify

Version 0.2.0

Build Status Dependency Status devDependencies

LESS 3.12 precompiler and CSS plugin for Browserify. Inspired by node-underscorify. Originally developed for TIME Magazine's interactive deployment framework.

When bundling an app using Browserify, it's often convenient to be able to include your CSS as a script that appends the style declarations to the head. This is particularly relevant for self-assembling apps that attach themselves to a page but otherwise have reserved real-estate on the DOM.

This small script allows you to require() your CSS or LESS files as you would any other script.

Installation

npm install node-lessify

Usage

Write your LESS or CSS files as you normally would, and put them somewhere where your script can find it.

Then simply require them as you might anything else:

require('./styles.less');
require('./mysite.css');

To compile the stylesheets, pass this module to browserify as a transformation on the command line.

browserify -t node-lessify script.js > bundle.js

How it works

The stylesheets are compiled (in the case of LESS), minified, and bundle into a function that creates a new <style> element and appends it to the <head> using native Javascript.

Imports

LESS allows one to @import other LESS files. This module synchronously imports those dependencies at the time of the bundling. It looks for the imported files in both the directory of the parent file and the folder where the module itself lives, so it should work so long as the paths in the @import commands are correct relative to the importing file, as usual. It is not currently tested for recursive importing.

Options

Text Mode

As requested, it is now possible to ask the transformation not to auto-append the css but merely to compile it into a string and assign it to a variable. This is accomplished by adding a package.json file in the directory from which browserify is run with the following properties:

"browserify": {
	"transform": [
		[ "node-lessify", {"textMode": true } ]
	]
}

See the dummy app in the test directory for an example of this in action.

Append Less file source URL

As a workaround to LESS source map issues (e.g. css style lines not referring to the correct LESS file), we can output only the source LESS file name for each require() call of a LESS file. This will at least allow us to distinguish STYLE elements.

Compile Options

Plugins

You can pass a plugins argument to get less plugins like autoprefix:

For example (from test.js):

var LessPluginAutoPrefix = require('less-plugin-autoprefix');
var autoprefix= new LessPluginAutoPrefix({ browsers: ["last 2 versions"] });

var b = browserify(sampleLESS);
b.transform(lessify, {
	compileOptions: {
		plugins: [autoprefix]
	}
});

Note: This does not currently work via package.json arguments, since the plugins need to be required separately, but we're working on it.

Paths

Pass a paths option to compileOptions to append search paths to less.render. These paths will be searched for any @import calls.

var b = browserify(sampleLESS);
b.transform(lessify, {
	compileOptions: {
		paths: [`${__dirname}/myproject/src/globals`],
	}
});

So we can now just do simple includes in any of our less files

@import colors.less; // Will look for myproject/src/globals/colors.less

Changes

v0.2.0:

  • Bumped version of Less to 3.12 (thx @fazod)
  • Added spec of Node version, min 6.0 per Less' requirements

v0.1.5:

  • Added support for (global) path specification (thx @relay-delivery)
  • Stopped overriding paths for more robust @includes (thx @lordvlad)
  • Improved Watchify support for error handling.
  • Updated error log messages for legibility/brevity

v0.1.3, v0.1.4: Added badges

v0.1.2: Updated dependencies

v0.1.1: Updated dependencies

v0.0.11: Watchify support. Thx, @jiaweihli!

v0.0.10: Supports backslashes in CSS. Thx, @BernieSumption!

v0.0.9b: README fixes

v0.0.9a: Allow for less plugins. Thx @henriklundgren!

v0.0.9: Read options from package.json the correct way, now that Browserify allows for it.

v0.0.8: More useful error statements with line and column numbers

v0.0.7: Now throws an error instead of failing silently if there's bad LESS, per Issue #8