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

bundle-module

v0.1.7

Published

Use Webpack to create a browser-friendly version of your npm module without muddying the repo

Downloads

10

Readme

Bundle Modules for the Browser

A no-config tool to bundle your apps into a single file using a remote Webpack configuration that spares you both the need for redundant local Webpack configuration files and an enormous glut of libraries in the node_modules directory of every project.

v0.1.7

Webpack is an incredible toolkit for compiling and transpiling Node modules for use in the browser. The only drawback, I've found, is that keeping the configuration files and their many dependencies in every local project directory can lead to a lot of bloat in node_modules and requires a fair degree of tedious copying and pasting when many projects use essentially the same configuration.

This module generates a configuration file outside the project and returns a packaged file for the browser in the project directory.

Installation

npm install -g bundle-module

Or, for the edge version:

npm install -g wilson428/bundle-module

Usage

Command Line

# cd /path/to/project
bundle-module --name=myproject

Node

const bundleModule = require('bundle-module');

bundleModule({
	entry: './myApp/index.js',
	filename: 'myApp.script.js',
	env: 'node',
	output_dir: './dist'
});

This basic usage will create a dist directory in your project with a file called myproject.js that can be included on a Web page in a single <script> tag. The project itself can include any local dependencies you wish -- D3, for example.

Command-line options

| Option | Purpose | Default | | :--- | :--- | :--- | | --env | The target environment for the build. Options are node or browswer | browser | | --version, -v | Return the version and exit | false | | --entry | The root Node file in your project to send to Webpack for compiling. | index.js | | --output_dir | The name of the local directory to contain the compiled file | dist | | --filename | The name used in the compiled file. There's no need to include .js. | bundle | | --name | The name of the global variable when exporting for the browser. | name (see above) | | --min, --minified | Whether to minify the output, which will automatically have the name [filename].min.js | false | | --watch | Whether to recompile after every file change | false | | --verbose | Whether to output the (long) configuration file| false |

Development vs. Production mode

Using --min defaults to production mode and generates bundle-min.js while omitting it builds an unminified, source-mapped bundle.js (whatever name you specified with --name instead of bundle). To save time, I recommend the following scripts in your package.json for a given app:

"scripts": {
	"build": "bundle-module --entry=./debug.js --name=script --env=node --output_dir=.",
	"build_verbose": "bundle-module --entry=./debug.js --name=script --env=node --output_dir=. --verbose",
	"watch": "bundle-module --entry=./debug.js --name=script --env=node --output_dir=. --watch",
	"minify": "bundle-module --entry=./debug.js --name=script-min --env=node --output_dir=. --min"
}

Or, if you want to build a distribution script to be included as a global variable via a <script> element, use --env=browser (or leave it out). The global variable will be give the --name parameter.

Supported loaders

At present, bundle-module will understand the following file types when included with import or require. If you commonly use a filetype that requires a different loader, such as a different templating engine, by all means let me know or, better yet, send me a PR!

  • .js: Javascript files are automatically transpiled with Babel, allowing you to write your module in ES6.
  • .json: Node understands JSON imports by default.
  • .css, .scss, .less: Includes the postcss-loader loader with the postcssPresetEnv plugin for autoprefixing.
  • .html, .ejs: You can either require plain HTML or Embedded JavaScript templates.
  • .csv, .dsv, tsv: You can require any sort of delimited data file, which will appear in the code like a JSON file.
  • .png, .jpe?g, .gif: Include images as base64 data. Be mindful of filesize.