Copy js from "Dependencies" from node_modules to a folder of my project with gulp

0

I have some doubts regarding this "new" tool of node/npm .

As far as I know / learned, I have great benefits of managing scripts js by npm . But I do not think it's too healthy to go through the node_modules folder of my project. Sometimes I realize that third-party libraries do not have a pattern on paths of scripts . So I wanted to understand a little more about this kind of practice: is it possible through gulp , do I copy the files from the node_modules folder to a given directory of my need outside of it?

ex:

  

/node_modules/jquery/dist/jquery.min.js to another directory outside   of node_modules.

( jquery is really just an example.) As I said, I know there are variations in folder patterns. So reaffirming my doubts: is there any more "elegant" solution to this scenario? My need is to "automate" a way to copy the third-party scripts to a folder of my need. I am also aware that I may have misunderstood this flow. Thank you.

    
asked by anonymous 14.08.2018 / 15:39

1 answer

1

Actually, this is the idea of working with node_modules and task automators, here is an example of how I work with scripts.

1) Read all the node_module scripts you want and compile them all into one main.JS along with your script file.

scripts = [
    'node_modules/prismjs/prism.js',
    'node_modules/flickity/dist/flickity.pkgd.min.js',
    'node_modules/select2/dist/js/select2.full.min.js',
    'base/scripts/main.js'
];

gulp.task('scripts', function() {
    return gulp.src(scripts)
        .pipe(plumber())
        .pipe(concat('main.js'))
        .on('error', gutil.log)
        .pipe(gulp.dest('assets/scripts'))
        .pipe(rename({suffix: '.min'}))
        .pipe(uglify())
        .pipe(gulp.dest('assets/scripts'));
});
    
07.11.2018 / 11:21