Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Copy a folder and subfolders without all the `node_modules` folders within... tested with Node v9.10.1
// yarn add fs-extra --dev
const fs = require("fs-extra");
console.log("*** start ***");
// replace ".src" with your own folder
fs
.copy("./src", "./dist", {
filter: path => {
// console.log("path ===", path);
// skip filter on files
if (fs.lstatSync(path).isFile()) return true;
// return false if path is directory and string contains node_modules
return !(path.indexOf("node_modules") > -1);
}
})
.then(() => {
console.log("folder copied successfully!");
console.log("*** end ***");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.