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

nessa

v0.0.23

Published

Virtualize your Pug templates

Downloads

28

Readme

nessa

Nessa was an Ainu and a Valië and was ranked the least among the Valar. She was notable for her speed, being fast "as an arrow in movement", for which reason she was called Nessa the Swift.

A Babel plug-in and Webpack loader which translate Pug templates into Hyperscript for virtual-dom diffing/rendering flows.

NPM

Installation

Add nessa to dev dependencies in package.json:

npm install --save-dev nessa

Either tell Babel to use this plug-in in .babelrc:

"plugins": [
  "nessa/library/transpiler",
]

Or tell Webpack to use this loader for .pug files in webpack.config.js:

var webpackConfig = {
  module: {
    loaders: [
      {
        test: /\.pug$/,
        loader: 'nessa/library/loader',
      },
    ],
  },

  // ...

};

Configuration

The recommended way to configure Babel options for nessa is with plug-in options, e.g.:

"plugins": [
  [
    "nessa/library/transpiler",
    {
      "isDebugged": true,
      "logPath": "./process/logs/nessa.babel.log",
      "require": {
        "utilities": "./library/utilities"
      },
      "test": "\\.pug$"
    }
  ]
]

The available options are:

  • isDebugged
  • logPath
  • require.utilities
  • test

The recommended way to configure Webpack options for nessa is with a top-level nessa object, e.g.:

var webpackConfig = {
  module: {
    // ...
  },

  'nessa': {
    'isDebugged': true,
    'logPath': './process/logs/nessa.webpack.log',
    'require': {
      'utilities': 'nessa/library/utilities'
    }
  }

  // ...
};

The available options are:

  • isDebugged
  • logPath
  • require.utilities

Usage

With Babel or Webpack configured as above, simply import/require (for Webpack) or require (for Babel) a Pug file to access the compiled template function, which returns a virtual-dom VNode instead of HTML:

const template = require('./index.pug');
let vtree = template({foo: 'bar'});

Example

A sample application that uses the Babel plug-in (and custom Utilities) can be found here.

Custom Elements

Custom elements can be included in templates. In the case of the Babel plug-in the custom element name is the variable name of the declared template, e.g.:

const WelcomeElement = require('./welcome.pug')
const Default = require('./default.pug')

... where welcome.pug is ...

h1 Welcome #{name}

... and default.pug is ...

div
  WelcomeElement(name=name)
  p #{name}'s Pug source code!

... and the Default template function is called passing a value for the name local variable only, e.g.:

let virtualNodes = Default({
    'name': 'Forbes'
  })

In the case of the Webpack loader the custom element name is the local name passed to the template function, e.g.:

import WelcomeElement from './welcome.pug'
import Default from './default.pug'

... where welcome.pug and default.pug are as above and the Default template function is called passing values for both the WelcomeElement custom element and the name local variable, e.g.:

let virtualNodes = Default({
    WelcomeElement,
    'name': 'Forbes'
  })

License

ISC