Last active
July 31, 2018 19:57
-
-
Save justinswelch/34802b4a4fe2721c40410ade178e17f2 to your computer and use it in GitHub Desktop.
Gulp task to copy NPM frontend dependencies from node_modules to ./dist/js/vendor/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*----------------------------------------------------- | |
* Copy NPM front-end dependencies to ./dist/ | |
* | |
* Tested with: | |
* Node: v10.6.0 | |
* NPM: 6.2.0 | |
* Gulp: 4.0.0-alpha.3 (and CLI 2.0.3) | |
*----------------------------------------------------*/ | |
gulp.task( 'copy-npm-deps', function ( done ) { | |
// store public dependencies from package.json into variable | |
let pkg = require( './package.json' ) | |
let dependencies = Object.keys( pkg.dependencies ) | |
// base directory paths | |
let node_path = "./node_modules/" | |
let dist_path = "./dist/js/vendor/" | |
// loop through each dependency and copy to dist_path | |
dependencies.forEach( function( dependency_dir ) { | |
let src = node_path + dependency_dir + '/**/*' | |
let dest = dist_path + dependency_dir | |
gulp.src( src ).pipe( gulp.dest( dest ) ) | |
}); | |
done(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment