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 🙏

© 2026 – Pkg Stats / Ryan Hefner

grunt-encase

v0.2.0

Published

concat and encase multiple JS files in an anonymous function to export any variable or inside an AMD Module

Readme

grunt-encase Build Status

Concat and encase in an anonymous function to export any variable or encase within a AMD module.
Test every possible individual files and variables can be selected to be published at release file.

Getting Started

Install this grunt plugin next to your project's with: npm install grunt-encase
Then add this line to your project's Gruntfile.js Gruntfile:

grunt.loadNpmTasks('grunt-encase');

For information about installing the Grunt, please see here
http://gruntjs.com/getting-started

Example

src1.js

// Does not need to be wrapped in an anonymous function.
var hoge = 'hogehoge';
...

src2.js

// Does not need to be wrapped in an anonymous function.
var piyo = 'piyopiyo';
...

dest.js

(function(s, undefined) {
  // concat src1.js and src2.js
  var hoge = 'hogehoge';
  ...
  var piyo = 'piyopiyo';
  ...
  
  // export variable can select with option.
  module.exports = {hoge: hoge, piyo: piyo}; // if enviroment is 'browser', window = {...}
})(someVariable);

Documentation

You'll need to install grunt-encase first:

npm install grunt-encase

Then modify your Gruntfile.js file by adding the following line:

grunt.loadNpmTasks('grunt-encase');

Then add some configuration for the plugin like so:

grunt.initConfig({
    ...
    grunt.initConfig({
      encase: {                         // Task
        develop: {                      // Target
          separator: '\n',              // Concat Separator
          enviroment: 'browser',        // Target Enviroment ('node' or 'browser')
          useStrict: true,              // 'use strict'
          banner: '<%= meta.banner %>', // Optional Banner
          exports: ['hoge', 'piyo'],    // Export Variables (string expression or variable names array)
          params: {"window": "w"},      // Params passed into anonymous function, key/value represents ... 
                                        // ... how they will be utilized in the function call argument vs function argument		   
          src: 'src/*.js',              // source (string expression or filenames array)
          dest: 'dest/build.js'         // destination
        }
      }
    });
    ...
});

Then just run grunt encase and enjoy!

The file content can be encased in a AMD Module by specifying "defines" attribute in the initConfig like below.

grunt.initConfig({
    ...
    grunt.initConfig({
      encase: {                         // Task
        develop: {                      // Target
          separator: '\n',              // Concat Separator
          enviroment: 'browser',        // Target Enviroment ('node' or 'browser')
          banner: '<%= meta.banner %>', // Optional Banner              
          exports: ['hoge', 'piyo'],    // Export Variables (string expression or variable names array)
          defines: {
            "jquery": "$",              // Params to be used in constructing the AMD 'define' function
            "backbone": "bb"
          },
          src: 'src/*.js',              // source (string expression or filenames array)
          dest: 'dest/build.js'         // destination
        }
      }
    });
    ...
});

Release History

  • 0.0.1 - initial release with a minimum feature
  • 0.0.2 - added support for Grunt v0.4.x
  • 0.0.3 - added support banner and useStrict option
  • 0.1.0 - added support auto exports amd-style or tranditional window-style in browser
  • 0.2.0 - dependency plugin version up and fixed some bug

License

Copyright (c) 2012-2015 Kokudori Licensed under the MIT license.