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-requirejs-jzaefferer

v0.2.14

Published

Using requirejs and almond with grunt

Downloads

2

Readme

grunt-require

Use @cowboys wonderful js based optimizer grunt together with @jrburkes r.js optimizer, to build your AMD based projects with grunt.

Now with almond goodness.

Build Status

Upgrade warning

I removed the 'clearTarget' config option from the plugin, because i want you all to go to grunt-contrib page and use their 'clean' task instead!

Getting Started

Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: npm install grunt-requirejs

Then add this line to your project's grunt.js gruntfile.

grunt.loadNpmTasks('grunt-requirejs');

Resources

Documentation

Load the grunt-requirejs task as described in 'Getting started' and add your r.js optimizer configuration to your grunt file:

Example require js optimizer grunt file config entry:


// ... grunt file contents
 requirejs: {
      dir: 'build',
      appDir: 'src',
      baseUrl: 'js',
      paths: {
          underscore: '../vendor/underscore',
          jquery    : '../vendor/jquery',
          backbone  : '../vendor/backbone'
      },
      pragmas: {
          doExclude: true
      },
      skipModuleInsertion: false,
      optimizeAllPluginResources: true,
      findNestedDependencies: true
    }

// ... even more grunt file contents

You see, there is no difference in declaring your require config when your using your gruntfile instead of using a separate requirejs config file.

Almond

If you like to replace require.js with almond.js during the build process, grunt-requirejs comes with an experimental almond injection mode. It even converts your require script calls in your html files to call the 'almondyfied' module, instead of calling require.js that then calls (e.g.) loads the module.

The only constraint for using the auto almond insertion is, that you at least define one module (mostly named 'main').

// ... grunt file contents
 requirejs: {
      // almond specific contents
      // *insert almond in all your modules
      almond: true,
      // *replace require script calls, with the almond modules
      // in the following files
      replaceRequireScript: [{
        files: ['build/index.html'],
        module: 'main'
      }],
      // "normal" require config
      // *create at least a 'main' module
      // thats necessary for using the almond auto insertion
      modules: [{name: 'main'}],
      dir: 'build',
      appDir: 'src',
      baseUrl: 'js',
      paths: {
          underscore: '../vendor/underscore',
          jquery    : '../vendor/jquery',
          backbone  : '../vendor/backbone'
      },
      pragmas: {
          doExclude: true
      },
      skipModuleInsertion: false,
      optimizeAllPluginResources: true,
      findNestedDependencies: true
    }

// ... even more grunt file contents

Special case, the 'out' property

If you define a special output name for your generated module file, you have to specify a "modulePath" property inside your "replaceRequireScript" configuration

requirejs: {
    almond: true,
    replaceRequireScript: [{
        files: ['index.html'],
        module: 'main',
        modulePath: '/js/main-build'
    }],
    baseUrl: "js",
    paths: {
        'Handlebars': 'libs/Handlebars',
        'Backbone': 'libs/backbone',
        'underscore': 'libs/underscore',
        'json2': 'libs/json2',
    },
    out: 'js/main-build.js'
}

require function not found after almond integration

First occured in issue #3. You probably have to set

requirejs: {
    wrap: true
}

like described here: https://github.com/jrburke/almond#usage

Dual Config

By default it is assumed that your are using the optimizer for only JS or CSS not both. However should you wish to use require.js to optimize your CSS in addition to your JS, this is possible using a dual config. This will allow you to maintain your config options for both your CSS and JS under the requirejs key in your grunt.js.


// ... grunt file contents
 requirejs: {

      js: {
        // config for js
      },

      css: {
        // config for css
      }

    }

// ... even more grunt file contents

Then when calling your task you can pass as an argument the mode your wish to run the task in.

grunt.registerTask('release', 'requirejs:css', 'requirejs:js');

or

> grunt requirejs:js
> grunt requirejs:css

If no argument is specified, then the task will look for the approprate config in the following order, JS, CSS and then finally it will use whatever config has been defined if neither JS or CSS is found.

Release History

0.2.12

  • fixes issue of r.js almond-based dependency mixup (added by @chrissrogers)

0.2.11

  • Fixed issue #17 (almond: false, causes build to fail)
  • Added example projects

0.2.10

  • Fixed issue #4
  • Fixed issue #8

0.2.9

  • Removed jQuery dependency and replaced it with cheerio
  • Updated versions of 3rd party libs

0.2.8

  • RequireJS Version bump to 2.0

0.2.7

  • Removed npm dependency for tracing the almond file
  • Added some informations in the readme about the almond 'wrap=true'

0.2.6

  • Added 'modulePath' configuration option for specifying your modules path
  • Added 'modulePath' documentation

0.2.5

  • Added dual config
  • Optimized almond integration (removed npm dependency)
  • Readme updates
  • requirejs isnt a multi task anymore

0.2.0

  • Removed clearTarget (use grunt-contrib clean instead)
  • Added almond integration
  • Added automatic almond js module script tag replacement for html files
  • Improved documentation

0.1.0

  • Initial Release

License

Copyright (c) 2012 asciidisco Licensed under the MIT license.