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

build-modules

v2.2.2

Published

`build-modules` ============

Downloads

155

Readme

build-modules

Easily build a umd package from a project of CommonJS (node.js style) modules that can be loaded via require.js or as a traditional browser global loaded in a <script> tag. Has an option to "watch" the source files and rebuild the package on the fly.

This uses webpack under the hood.

Install

npm install build-modules

Example

var build = require('build-modules')
var emitter = build(__dirname+'/rootDirectory/moduleName', {output:{path: __dirname+'/generatedFile/'}})
emitter.on('done', function() {
   console.log("Done!")
})
emitter.on('error', function(e) {
   console.log(e)
})
emitter.on('warning', function(w) {
   console.log(w)
})

Why use build-modules over Browserify and Webpack?

If you just want to easily support people using require.js and traditional script inclusion, but don't need anything complicated, this module is for you. It also exposes the "watcher" ability from webpack (which browserify doesn't have).

Usage

build(filepath, options)
  • filepath - The absolute path to the module file.
  • options - An object with optional parameters. Can contain the following members:
    • watch - If true, sets up a watcher that rebuilds the bundle whenever relevant source files change (keeps running until the process closes)
    • name - The name of the global variable in the case the UMD package is loaded without a module system (defaults to path.basename(filepath))
    • header - A string to put at the top of the build bundle.
    • output - An object with the members:
      • path - Where to put the bundle file (defaults to the entrypoint directory)
      • name - What to name the output bundle (defaults to options.name+'.umd.js')
    • alias - Webpack alias option.
    • plugins - Additional webpack plugins to add.
    • jsonpFunction - The name of the jsonp function name (defaults to webpack's default).
    • minify - If false, this doesn't minify and also adds pathinfo to modules in the bundle. Default: true.
    • sourceMap - (Default:true) If false, won't produce a source map. If true, will use the 'source-map' webpack devtool option. If something else, it'll set the webpack devtool option to that value.

Outputs the following files:

  • A minified universal module
  • A sourcemap file

Known issues

When build is called with the watch option, 'done' is emitted twice in a row on the first run. After that, you just get the expected 1 per build.

Change Log

  • 2.2.0 - Adding sourceMap option
  • 2.1.0 - updating to webpack 3
  • 2.0.6 - turning off verbose webpack messages
  • 2.0.5 - Fixing pathinfo
  • 2.0.4 - (minor) slight improvement in how context is done under the hood, and an extra test
  • 2.0.3 - adding a 'minify' parameter that allows you to turn off minifying (for debugging purposes)
  • 2.0.2 - fixing building modules that require files below their directory
  • 2.0.0 - BREAKING CHANGE
    • Using webpack instead of browserify
    • Parameters all change
    • A watching rebuilder can be configured now
  • 1.0.12 - Updating to fix breaking change in browserify. Also shrinkwrapping so this never happens again.
  • 1.0.10 - upgrading modules so no dependencies have post-install scripts (which npm chokes on very often)
  • 1.0.9
    • deprecating this module
    • adding bundle options to support sourcemaps (this is probably the last addition that will be made to this module)
  • 1.0.4 - changing api to pass in the module path as the 4th parameter instead of the module contents
  • 1.0.2 - now uses browserify and just outputs umd packages.
  • 1.0.1 - now supports modules with dependencies!

License

Released under the MIT license: http://opensource.org/licenses/MIT