copy-node-modules - fast Node.js modules deployment to destination directory
Copy all modules listed in dependencies
or/and devDependencies
field of package.json
to destination directory.
The procedure:
- Read
package.json
from source directory and readdependencies
ordevDependencies
field. - Search for existing modules and ther dependencies in source directory.
- Copy all modules to destination directory.
Modern applications use lots of modules, each module depends on more modules resulting in hundreds of modules being installed when typing npm install
. This module will help you to save time from slow npm install
when you want to pack/deploy your application to a directory which contains all needed modules.
It will save you a bunch of time to deploy a stand-alone application from existing development directory, no need to fetch all modules from remote repository.
Installation
yarn add copy-node-modules --dev
or
npm install copy-node-modules --save-dev
Programmatic Usage
ES6+ environment:
const copyNodeModules = ;
ES6+ environment with import
support:
;
ES5
var copyNodeModules = ;
copyNodeModules(srcDir, dstDir, [options], callback)
-
srcDir
: source directory containingpackage.json
file. -
dstDir
: destination directory to copy modules to (modules will be copied todstDir/node_modules
directory). -
options
:devDependencies
: boolean value, defaults to false, showing whether modules indevDependencies
field ofpackage.json
should also be copied (when it's set to true).concurrency
: integer value, max number of root packages whose files are being copied concurrently.filter
:RegExp
or function that accepts one value (the full path) and returns a boolean (copy on true).
-
callback(err, results)
: A callback which is called when all copy tasks have finished or error occurs,results
is an array contains copied modules, each item is an object as{name: 'xxx', version: 'xxx'}
Examples
const copyNodeModules = ;const srcDir = '/somewhere/project';const dstDir = '/somewhere/project/dist';;
Example with a filter method
const copyNodeModules = ;const srcDir = '/somewhere/project';const dstDir = '/somewhere/project/dist'; // Filter method that will ignore node_module folders in a node moduleconst filter = { const firstIndex = path; return v === -1;} ;
CLI Usage
copy-node-modules src_dir dest_dir [-d|--dev] [-c|--concurrency] [-v|--verbose] [-f|--filter]
src_dir
: source directory containingpackage.json
file.dest_dir
: destination directory to copy modules to (modules will be copied todest_dir/node_modules
directory).-d|--dev
: whether modules indevDependencies
field ofpackage.json
should be also copied.-c|--concurrency
: max number of root packages whose files are being copied concurrently.-v|--verbose
: verbose mode.-f|--filter
: regular Expression, files that match this expression will be copied; it also matches directories fi: -findex.html
matchespath/index.html
but notpath/
and because of thisindex.html
is not copied.
License
MIT