A
A
Alexander2019-02-06 23:28:48
npm
Alexander, 2019-02-06 23:28:48

How to save dependencies npm packages to another folder and hook the main files?

When using Bower, the .bowerrc file is written "directory" : "src/libs/"to save packages to the libs folder. The bower.json file contains overrides, where the paths to the main files are registered. With the help main-bower-files, I pick up the main files and throw them into the right folder. All this only applies to package dependencies.
Question! How to implement all the same but only without using Bower? For example, purely in npm or yarn.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2019-02-07
@delphinpro

How, how .. Javascript on the jamb =)))
Need to copy files? No problem! Let's write a copy task.

global.ROOT = 'корень проекта';
let config = {
  root: {
    build: 'dist'
  }
};

config.copy = [
    { src: 'source/assets/**', dest: '/'},
    { src: 'source/assets/.htaccess', dest: '/'},
    { src: 'node_modules/tiny-slider/dist/tiny-slider.js', dest: '/design/js' },
    { src: 'node_modules/tiny-slider/dist/tiny-slider.css', dest: '/design/css' },
    { src: 'node_modules/cool-menu/dist/cool-menu.js', dest: '/design/js' },
    { src: 'node_modules/svg4everybody/dist/svg4everybody.js', dest: '/design/js' },
    { src: 'node_modules/vanilla-text-mask/dist/vanillaTextMask.js', dest: '/design/js' },
    { src: 'node_modules/tippy.js/dist/tippy.all.min.js', dest: '/design/js' },
];

function copyFiles(conf, options) {
    return new Promise((resolve, reject) => {

        if (!('src' in conf)) reject('Invalid config for "copy" task: undefined "src" param');
        if (!('dest' in conf)) conf.dest = '';
        if ('extensions' in conf) { }

        let source = path.join(global.ROOT, conf.src);
        let dest   = path.join(global.ROOT, options.root.build, conf.dest);

        let pipeline = gulp.src(source).pipe(gulp.dest(dest));

        pipeline.on('error', function (err) {
            reject(err);
        });

        pipeline.on('end', function () {
            resolve();
        });

  });
}

gulp.task('copy', function(done){
  
  let copies = [];

  options.copy.forEach(item => {
    copies.push(copyFiles(item, options));
  });

  Promise.all(copies).then(value => done(), reason => done());
  
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question