List only needed modules to package/archive/zip before going to production (packaging of AWS Lambda, for example)
npm install --save-dev @redneckz/slice-node-modules
Using npx:
npx @redneckz/slice-node-modules \
[-e <source file>] [-p <package.json>] \
[--dev|-D] \
[--print0|-0] \
[--include <glob>] [--exclude <glob>] \
[--zip <zip file>]
List all packages used by some-package
:
$ # Parse dependencies from source files (-e stands for entry file)
$ npx @redneckz/slice-node-modules -e some-package/lib/index.js
$ # or from package.json
$ npx @redneckz/slice-node-modules -p some-package/package.json
Dev. dependencies:
$ npx @redneckz/slice-node-modules -e some-package/lib/index.js --dev
Filtering options --include/--exclude:
$ npx @redneckz/slice-node-modules -e some-package/lib/index.js --exclude 'aws-*'
Zero-separated (for xargs
, for example):
$ npx @redneckz/slice-node-modules -e some-package/lib/index.js --print0
In case of monorepo (just for example):
$ npx @redneckz/slice-node-modules \
-e monorepo-root/packages/some-lambda/lib/index.js \
--exclude 'aws-*' \
--zip some-lambda.zip
AWS Lambda config (CloudFormation):
const logLambda = new Function(this, 'some-lambda', {
code: new AssetCode('some-lambda.zip'),
handler: 'monorepo-root/packages/some-lambda/lib/index.handler',
runtime: Runtime.NODEJS_12_X
});