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

@prantlf/grunt-contrib-requirejs

v2.0.1

Published

Optimize RequireJS projects using r.js. Forked to use a custom r.js module.

Downloads

27

Readme

@prantlf/grunt-contrib-requirejs

Latest version Dependency status

Optimize RequireJS projects using r.js. Forked to use a custom r.js module.

Changes made in this fork:

  • A new option requirejs allows passing a custom build of r.js to the task.
  • A new option force suppresses failures and lets other tasks continue if the current one failes.
  • A new option verbose enables verbose logging of r.js in addition to the command line option.

Getting Started

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 @prantlf/grunt-contrib-requirejs --save-dev

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

grunt.loadNpmTasks('@prantlf/grunt-contrib-requirejs');

This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.3.

Requirejs task

Run this task with the grunt requirejs command.

Task targets and options may be specified according to the grunt Configuring tasks guide.

Options

For a full list of possible options, see the r.js example build file.

done(done, build)

The done option is an optional hook to receive the r.js build output. The first argument is the grunt async callback that you are required to call if you provide the done hook. This informs grunt that the task is complete. The second parameter is the build output from r.js.

error(done, error)

The error option is an optional hook to receive the r.js error. The first argument is the grunt async callback that you are required to call if you provide the done hook. This informs grunt that the task is complete. The second parameter is the error instance thrown from r.js in case of failure.

requirejs

The requirejs option is an object exported from a module compatible with r.js. You can pass an alternative optimizer version to the task by this option. The module requirejs is initialised by require('@prantlf/requirejs') by default.

logLevel

The logLevel option is a number to be passed to the r.js as the log level. The values can be 0 (tracing), 1 (information), 2 (warning) or 3 (error). The default if 2 (warning).

verbose

The verbose option is a boolean to enable logging at the level 0 (tracing) if set to true. The default is false.

force

The force option is a boolean, which if set to true, forces the grunt running and executing further tasks, although the current task failed. The default is false.

Usage Examples

requirejs: {
  compile: {
    options: {
      baseUrl: 'path/to/base',
      mainConfigFile: 'path/to/config.js',
      name: 'path/to/almond', /* assumes a production build using almond, if you don't use almond, you
                                 need to set the "includes" or "modules" option instead of name */
      include: [ 'src/main.js' ],
      out: 'path/to/optimized.js'
    }
  }
}

Done

requirejs: {
  compile: {
    options: {
      baseUrl: 'path/to/base',
      mainConfigFile: 'path/to/config.js',
      done: function(done, output) {
        var duplicates = require('rjs-build-analysis').duplicates(output);

        if (Object.keys(duplicates).length) {
          grunt.log.subhead('Duplicates found in requirejs build:');
          grunt.log.warn(duplicates);
          return done(new Error('r.js built duplicate modules, please check the excludes option.'));
        }

        done();
      }
    }
  }
}

Error

requirejs: {
  compile: {
    options: {
      baseUrl: 'path/to/base',
      mainConfigFile: 'path/to/config.js',
      error: function(done, err) {
        grunt.log.warn(err);
        done();
      }
    }
  }
}

Requirejs

requirejs: {
  compile: {
    options: {
      requirejs: require('@my/requirejs'),
      baseUrl: 'path/to/base',
      mainConfigFile: 'path/to/config.js',
      include: [ 'src/main.js' ],
      out: 'path/to/optimized.js'
    }
  }
}

License

Copyright (c) 2012-2016 Tyler Kellen, contributors Copyright (c) 2021-2023 Ferdinand Prantl

Licensed under the MIT license.