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

v1.1.1

Published

Transform AMD and UMD modules to CommonJS, globals, and so on.

Downloads

3

Readme

grunt-transform-amd

Build status Dependencies devDependencies NPM version

Transform AMD and UMD modules to CommonJS, globals, and so on.

Getting Started

This plugin requires Grunt ~0.4.1

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-transform-amd --save-dev

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

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

The "transform_amd" task

Overview

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

grunt.initConfig({
  transform_amd: {
    bundle1: {
      options: {
        root: 'uhop.test',
        browserGlobals: {
          'boom':    'BOOM',
          './d':     '!uhop.D',
          './sub/f': '!uhop.F'
        },
        replacements: {
          'c.js': 'shim.js'
        }
      },
      cwd:  'tests',
      src:  ['**/?.js', '!out/**'],
      dest: 'tests/out'
    }
  }
});

Documentation

This plugin wraps a functionality of heya-globalize package. See its README for the background information.

The plugin takes all its file-related information using normal grunt features: cwd as a virtual root directory for our input files, src as a list of files to process, dest as a directory where to put an output.

Following options are recognized:

  • options.root — a root variable for a package as a string. In heya-globalize it is specified as browserGlobals["!root"].
  • options.replacements — specifies a map to substitute one file names with another, so it is possible to include shims specific for a browser. If a value is specified, yet falsy, that module will be ignored, and not converted. It is similar to browser section of package.json.
  • options.browserGlobals — a dictionary to map modules to globals. It is thoroughly documented in heya-globalize with two important differences:
    1. Property !root is unused — use options.root instead.
    2. Property !dist is unused — use dest instead.
  • options.loaders — an array of strings. Those strings will be searched verbatim at the beginning of each file. If found they will be replaced by a different loader. If not specified, a Heya-style UMD loader will be looked for. In any case define will be tried as well, which will be replaced by a new loader too.
  • options.newLoader — a string or a function, which defines a new loader.
    • If "--amd", a static AMD loader will be used ("define").
    • If "--cjs", a CommonJS loader will be generated.
    • If "--es6", an ES6 module loader will be generated (compatible with Babel).
    • Any other string will be used as a static loader.
    • If a function, it should return a dynamically generated loader as a string, when called with following parameters:
      • deps — dependencies as an array of strings.
      • mod — module name as a string.
      • from — file name as a string.
    • If not specified, a loader based on browser globals will be dynamically generated.
  • options.silent — a Boolean. If true all informational output is suppressed. Default: false.

Please take a look at Gruntfile.js of this project as well as a content of tests/ directory to understand the conversion process better. Run npm test, and inspect generated files in tests/out/. Files a.js, b.js, and c.js contain the Heya-style UMD loader string (allows a module to work seamlessly in AMD and CommonJS environments). Other files use AMD's define(). A generated test can be found in tests/test-module.js.

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.

Release History

  • 1.1.1 — Refreshed dependencies to incorporate bugfixes upstream.
  • 1.1.0 — Support for generating AMD/CommonJS/ES6 modules.
  • 1.0.3 — Minor bugfixes.
  • 1.0.2 — Added silent option.
  • 1.0.1 — Now it works with dynamic expansion.
  • 1.0.0 — The initial release.

License

BSD