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

grunt-jade-filerev-usemin

v0.0.1

Published

replace references to script/css in jade file with minified revved script/css from filerev

Downloads

6

Readme

grunt-jade-filerev-usemin

Grunt plugin for replacing resources in jade files with minified and revved js & css files

NPM Version NPM Gittip Dependencies Built with Grunt

Getting Started

This plugin requires Grunt.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-jade-flerev-usemin --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-jade-filerev-usemin');

The "jadeFilerevUsemin" task

This project is shamelessly borrowing from grunt-jade-usemin Project, which is based on the grunt-usemin Project. grunt-jade-filerev-usemin is meant to be an assisting tool in preparing projects for build. It was created to make grunt-jade-usemin work together with grunt-filerev.

The plugin will scan the parsed .jade files and replace the script/css with the minified ones (this plugin will not concatenate nor minify your script/css).

Use grunt-jade-usemin to concatenate and minifiy your script/css, then use grunt-filerev to rename minified script/css with revision number. grunt-jade-filerev-usemin as the last step will correctly replace the reference to script/css in the jade file.

How to use in a Jade file

The original grunt-jade-usemin relies on environment variable in express to determine whether to use unminified or minified resources.

jadeFilerevUsemin instead creates a new jade file with resources replaced with the minified one. This may be necessary if you are also renaming minified resouces with grunt-filerev.

jadeFilerevUsemin relies on grunt-jade-usemin to concatenate and minify the script/css.

jadeFilerevUsemin relies on grunt-filerev to rename the minified script/css with the revisioned one.

jadeFilerevUsemin simply scans for the following line: <!-- build:<type> <target -->. Where <target> can be either js or css.

jadeFilerevUsemin then adds the scripts/styles inside the lines until it meets the closing line: <!-- endbuild --> Which signifies the end of a usemin target.

This is an example index.jade:

//-<!-- build:js test/compiled/compiled.min.js -->
script(src='/test/fixtures/script1.js')
script(src='/test/fixtures/script2.js')
//-<!-- endbuild -->

Running **jadeFilerevUsemin** on this file will replace the block with

//-<!-- build:js test/compiled/compiled.min.js -->
script(src='/test/compiled/compiled.min.eba0f92b.js')
//-<!-- endbuild -->

Revision number is based on the hash and is produced by grunt-filerev.

Another example is using jadeFilerevUsemin with css files:

//-<!-- build:css test/compiled/style.min.css -->
link(rel='stylesheet', href='/test/fixtures/style1.css')
link(rel='stylesheet', href='/test/fixtures/style2.css')
//-<!-- endbuild -->

Above block will be replaced by

link(rel='stylesheet', href='/test/compiled/style.min.23f8haf2.css')

Available Options

Deprefix_dest

{String} [deprefix_dest=''] This is nearly the opposite of what prefix does in grunt-jade-usemin. Prefix maps from server based href location to file location relative to Gruntfile, by prefixing. Deprefix_dest maps from file location (of the minified revved file) to server based href location, by stripping prefix.

Gruntfile.js basic task

In your project's Gruntfile, add a section named jadeFilerevUsemin to the data object passed into grunt.initConfig().

grunt.initConfig({
  jadeUsemin: {
    main: {
      options: {
        prefix: '', //optional - add prefix to the path [default='']
        deprefix_dest: '', //optional - add prefix to the path [default='']
      },
      src: 'src/index.jade',
      dest: 'src/index.jade',
    }
  },
})

Example build task may be defined as follows:

  grunt.registerTask('build', [
    "jadeUsemin",
    "filerev",
    "jadeFilerevUsemin",
  ]);

Usage Examples

Default Options

grunt.initConfig({
  jadeUsemin: {
    main: {
      options: {
        prefix: './public/',
        deprefix_dest: '.dist/public',
      },
      src: "server/views/index.jade",
      dest: ".dist/server/views/index.jade",
    }
  },
})

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2014 noos. Licensed under the MIT license.