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

pugjs-brunch

v2.11.3

Published

Adds Pug (aka Jade) support to brunch.

Downloads

56

Readme

pugjs-brunch

npm Version Windows build Build Status License

Adds Pug v2.x (aka Jade) support to Brunch

This plugin compiles templates into any of three types:

  • Dynamic: Parameterized function that creates HTML at runtime based on the received parameters.
  • Precompiled: Returns raw HTML string with minimum overhead at runtime.
  • Static: Plain HTML files from pug templates in the assets directory.

See the changes for this version in the CHANGELOG.

Install

npm install pugjs-brunch --save-dev
# or
yarn add pugjs-brunch -D

or through devDependencies in package.json:

  "pugjs-brunch": "^2.11.2",

To compile pug into static, plain HTML, just place your files into the assets directory (usually app/assets).

The runtime

For modules, unless the inlineRuntimeFunctions option is set to true (not recommended), it is neccesary the Pug runtime, a small set of functions that lives in the global variable pug.

If required, the plugin loads a runtime from its own directory, so you don't have to worry about this.

NOTE:

Under certain circumstances the loading of the runtime may fail. If this happens to you, move pug_runtime.js from node_modules/pugjs-brunch/vendor to your vendor folder and load it in the global scope. Example:

  // In your brunch config
  plugins: {
    pug: { pugRuntime: false }
  }
  <!-- in your index.html file -->
  <script>
    require('pug_runtime')
    $(document).ready(function() {
      require('app')
    })
  </script>

Options

The plugin uses the plugins.pug section of your brunch-config and defines this properties:

Name | Type | Default | Notes --------------- | ------- | ---------- | ----------- locals | any | | Plain JavaScript object passed to Pug for static compilation. staticBasedir | string | (brunch) | Brunch convention.assets folder as string. This is the root of static templates. staticPretty | boolean | true | Pug's pretty option for files in staticBasedir, see NOTE (v2.8.5). preCompilePattern | RegExp | /.html.pug$/ | pre-compile the templates matching this regex (v2.8.6). pugRuntime | boolean | true | Set to false if you want to load another runtime. sourceMap | boolean | true | Defaults to brunch sourceMaps (with 's') value, false disables it (v2.8.4).

Note

From v2.11.1 staticPretty is set to false for production builds. Thanks to @stawberri

You can use any Pug options as well, pugjs-brunch set this:

{
  doctype: 'html',
  basedir: 'app',      // or wherever Brunch config says
  compileDebug: true,  // false if brunch `optimize` mode is 'production'
}

TIP:

Use preCompilePattern: /\S/ to evaluate all the templates at build time.

About staticBasedir

This option is only meaningful if you changed the default value of conventions.assets in the Brunch config and you are using absolute paths in includes or extends. This value will be pass to Pug as basedir when compiling static assets as html (see the pug options).

NOTE:

The options pretty and compileDebug are forced to false in production mode.

Examples

Dynamic templates

  // brunch-config.js
  ...
  plugins: {
    pug: {}
  },
  //- app/views/tmpl.pug
  p= name
  // in the js code
  ...
  const tmplFn = require('views/tmpl.pug')
  $('#elem').html(tmplFn({ name: 'John Doe' }))
  // now #elem contains <p>John Doe</p>

Precompilation

  // brunch-config.js
  ...
  plugins: {
    pug: {
      locals: { name: 'John Doe' },
      preCompilePattern: /\.html\.pug$/
    }
  },
  //- app/views/tmpl.html.pug
  p= name
  // in the js code
  ...
  const htmlStr = require('views/tmpl.html.pug')
  $('#elem').html(htmlStr)
  // now #elem contains <p>John Doe</p>

Static files

  // brunch-config.js
  ...
  plugins: {
    pug: {
      locals: { name: 'John Doe' }
    }
  },
  //- app/assets/user.pug
  doctype html
  html
    head
      meta(charset="utf-8")
    body
      p= name

will create the file ./public/user.html

Using with jscc-brunch

  ...
  plugins: {
    jscc: {
      values: {
        _APP: 'My App'  // $_APP can do static replacement
      },
      pattern: /\.(?:js|pug)$/,
      sourceMapFor: /\.(?:js|pug)$/,
      sourceMap: true
    },
    pug: {
      globals: ['$_APP']
    }
  }
  ...

Support my Work

I'm a full-stack developer with more than 20 year of experience and I try to share most of my work for free and help others, but this takes a significant amount of time and effort so, if you like my work, please consider...

Of course, feedback, PRs, and stars are also welcome 🙃

Thanks for your support!

License

The MIT License (MIT)

© 2016-2018 Alberto Martínez