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-amd-dist

v0.4.5

Published

Builder for AMD-based projects

Downloads

7

Readme

grunt-amd-doc

grunt-amd-doc is a grunt task to build JavaScript projects which use the AMD format.

Installataion

From the same directory as your Gruntfile, run

npm install grunt-amd-dist

Then add the following line to your Gruntfile:

grunt.loadNpmTasks('grunt-amd-dist');

You can verify that the task is available by running grunt --help and checking that "dist" is under "Available tasks".

Usage

grunt-amd-dist reads two sections of your config: dist and requirejs. dist can contain these properties (example from deferreds.js):

dist: {
	//path of the built file
	out: 'dist/deferreds.js',
	//remove requirejs dependency from built package (using almond)
	standalone: true,
	//build standalone for node or browser
	env: 'node',
	//env: 'browser',
	//if env === 'browser', this is the property under `window` which is
	//assigned the exported modules
	exports: 'deferreds',
	//String or Array of files for which to trace dependencies and build
	include: 'src/deferreds/**/*.js',
	//exclude files from the 'include' list. Useful to add specific
	//exceptions to globbing.
	exclude: [],
	//exclude files and their dependencies from the *built* source
	//Difference from 'exclude': files in 'excludeBuilt' will be
	//excluded even if they are dependencies of files in 'include'
	excludeBuilt: [],
	//exclude files from the *built* source, but keep any dependencies of the files.
	excludeShallow: []
},

requirejs is a standard r.js configuration object. grunt-amd-dist uses basePath, paths, and packages (all optional) to transform file names to AMD module names.

Once these options are in place, grunt dist will run grunt-amd-dist.

Standalone build

The standalone option will cause the built file to export an object containing all AMD modules which were part of the build. Depending on the env option, this returned object is assigned to module.exports (node) or window.<config:dist.exports. Object keys are the module names, values are the modules.

Why?

The r.js optimizer already performs the main purpose of grunt-amd-dist, so why use this grunt task? Well, the main use case for grunt-amd-dist is building library projects, where a build should include all files. Normally, AMD libraries should be used as-is and built by the consumer as part of their own projects' builds (to minimize the amount of library code included to what is actually used). A library built through grunt-amd-dist, then, would normally be intended as an alternative for consumers who do not want to use an AMD loader. With that in mind, here's what grunt-amd-dist provides:

  1. Can specify files instead of module names, and use grunt's (globbing)[https://github.com/gruntjs/grunt/blob/0.3-stable/docs/api_file.md#gruntfileexpand] to cut down on typing included files explicitly.
  2. Built script can export an object containing all included modules, for use outside AMD loaders.
  3. Can export for node or browsers.