node-sync-glob
Synchronize files and folders locally by glob patterns, watch option included.
Install
npm i sync-glob
Usage
Usage: bin/sync-glob.js <sources> <target> Commands: sources One or more globs, files or directories to be mirrored target Destination folder
package.json
In your You may have some build script in your package.json involving mirroring folders (let's say, static assets), that's a good use-case for sync-glob
:
// Before "scripts": "build": "cp -rf src/images dist/" "watch": "???" // After "devDependencies": "sync-glob": "^1.0.0" "scripts": "build": "sync-glob 'src/images/*' dist/images" "watch": "sync-glob --watch 'src/images/*' dist/images"
Important
Make sure that your globs are not being parsed by your shell by properly escaping them, e.g.: by quoting '**/*'
.
Exclude stuff
To exclude stuff from source just use glob exclusion - !
prefix, like:
"scripts": "sync": "sync-glob 'src/images/*' '!src/images/excluded.jpg' dist/images"
Windows
As node-glob
and node-glob-all
respectively only support unix style path separators /
, don't use windows style \
.
Please only use forward-slashes in glob expressions.
Though windows uses either
/
or\
as its path separator, only/
characters are used by this glob implementation. You must use forward-slashes only in glob expressions. Back-slashes will always be interpreted as escape characters, not path separators.Results from absolute patterns such as
/foo/*
are mounted onto the root setting usingpath.join
. On windows, this will by default result in/foo/*
matchingC:\foo\bar.txt
.
API
Check our API documentation
Credit/Inspiration
This package was mainly inspired by node-sync-files
.
I mainly kept the API as is, but enhanced the file matching by utilizing powerful globs.
Additionally it is a complete rewrite in ES6 and it does not suffer from outdated dependencies.
Some fancy features like --transform
is inspired by cpx
Proudly brought to you by <scale-unlimited>