README
Small
Small is a CommonJS bundler that aims to generate the smallest bundle size. It supports commonjs files, and output as a standalone, commonjs, amd and universal package.
Features
- Bundles CommonJS files
- Small file size
- Source map
- Supports circular dependencies
- Fits into gulp build system
How to install
npm install small
or (for command line usage)
npm install small -g
How to use
Command line:
small -i index.js -o output.js
(small --help
for more info)
From Node:
var small = require('small');
small.compile('index.js', options, function(error) {
if (error) throw error;
console.log('Completed');
});
Or, as a gulp plugin:
var gulp = require('gulp');
var small = require('small').gulp; // <-- notice the '.gulp' part
gulp.task('scripts', function() {
return gulp.src('lib/*.js')
.pipe(small())
.pipe(gulp.dest('release'));
});
This will create a bundle, starting with lib/index.js
. The output is saved as release/index.js
. You can customize this using the fileName (defaults to index.js
) and options parameters:
.pipe(small('foo.js', options))
Sourcemaps
The command line interface and Node api generate source maps by default. When using gulp, you can add gulp-sourcemaps to generate source maps:
var sourcemaps = require('gulp-sourcemaps');
gulp.task('scripts', function() {
return gulp.src('lib/*.js')
.pipe(sourcemaps.init())
.pipe(small())
.pipe(sourcemaps.write())
.pipe(gulp.dest('release'));
});
Options
options
in the examples above is an object with these properties:
outputFileName - The output filename(s). Example:
{
standalone: 'output.js',
}
Or
{
commonjs: 'output.commonjs.js',
amd: 'output.amd.js',
standalone: 'output.standalone.js',
universal: 'output.universal.js'
}
Default: { standalone: startFileName }
exportPackage - Export the package with the specified name. You can specify different names for different targets. Example:
{
commonjs: 'myCommonJSPackage',
amd: 'myAMDPackage',
standalone: 'myBrowserPackage'
}
Or
{
universal: 'myPackage'
}
globalModules - Add external modules, which will not be included in the generated package. Example:
{
'