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

Asked

Viewed 124 times

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 for npm. But I don’t think it’s very healthy to go through the briefcase node_modules of my project. Sometimes I realize that third party libraries do not have a standard on paths of scripts. So I wanted to understand a little bit more about this kind of practice: it’s possible through gulp, i copy the files from the folder node_modules for a given directory of my need out of it?

ex:

/node_modules/jquery/dist/jquery.min.js for another outside directory of the node_modules.

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

1 answer

1


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

1) Read all the node_module scripts you want and compile them all in a 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'));
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.