1.1.2 • Published 7 years ago

npm-baler v1.1.2

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
7 years ago

npm-baler

producing smaller node/npm deployments by bundling dependencies into a single file

  • detect dependencies from package.json
  • filter any ignored packages from .balerignore
  • create webpack entry file that exports dependencies
  • generate script to use sed to replace require with baler where possible
  • generate script to run before packaging for deployment

requirements

  • node
  • npm

recommended (to run generated scripts):

  • bash
  • find
  • xargs
  • sed

backup

this is experimental, please make a backup before trying baler

quick start

cd myproject
npm i
npm i -D npm-baler
# add "baler": "npm-baler" to npm scripts
npm run baler
# add global.baler = require('../baler.min.js'); in src/main.js
bash baler-replace.sh
bash baler-production.sh

install your modules

npm i

install baler

npm i -D npm-baler

add baler script to package.json

scripts: {
  "baler": "npm-baler"
}

run baler

npm run baler

baler shows the packages it's packing

                  _       _
 ___ ___ _____   | |_ ___| |___ ___
|   | . |     |  | . | .'| | -_|  _|
|_|_|  _|_|_|_|  |___|__,|_|___|_|
    |_|

{ ignores: [ 'some-lib' ],
  deps: [ 'timer-emitter' ],
  list: [ 'timer-emitter' ] }

bale will include packages:
timer-emitter

bale will NOT include packages:
some-lib

extraneous ignores:
some-lib

baler-replace script

baler generates a bash script that will replace require with baler where a baled package is used

this script requires bash, find, xargs and sed

e.g.

#!/bin/bash
SRC=src
echo "replace require('async') -> baler('async')"
find $SRC -type f -print0 | xargs -0 sed -i -e "s#require('async')#baler('async')#g"
find $SRC -type f -print0 | xargs -0 sed -i -e 's#require("async")#baler("async")#g'

you may need to modify SRC in this script if your source is not in src

run baler replace script

bash baler-replace.sh

add baler to your program entry point

this places the baler function in global scope, this must be done before using baler(...)

global.baler = require('../baler.min.js'); // comment to use require
// global.baler = require; // comment to use baler

add eslint rule

this stops eslint reporting that baler is undefined

"globals": {
  "baler": true
}

baler-production script

baler generates a script to be run after baling on production deployments

this uninstalls any packages that were baled and are no longer needed in node_modules

e.g.

#!/bin/bash
npm uninstall --no-save async body-parser express fs-extra timer-emitter uuid
npm prune --production

this script requires bash and npm

run baler production script

bash baler-production.sh

ignoring packages

any packages listed in .balerignore will not be baled and baler-production.sh will not uninstall them

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago