S
S
Sergey2018-05-23 22:16:27
Node.js
Sergey, 2018-05-23 22:16:27

Why does Gulp generate such a path when using the path module?

The standard task of copying files from one directory to another:

gulp.task('copy', function() {
  gulp.src('src/css/**/*').
    pipe(gulp.dest('dist/assets/css'));
});
// По умолчанию Gulp считает корневой директорией всё,
// что находится до шаблона **/* , поэтому результатом является путь
// dist/assets/css/**/*, что нам и надо

Same task, but using the path module :
gulp.task('copy', function() {
  // плагин path + пути, прописанные в файле конфигурации
  var src = path.join(path1, path2), // src/css/**/*
      dest = path.join(path3, path4); // dist/assets/css

  gulp.src(src).
    pipe(gulp.dest(dest));
});
// dist/assets/css/src/css/**/*

Why does the path change if the src and dest variables store the same values, and how to solve this problem? For now, the only option is to explicitly set the base: "src/css" property.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2018-05-25
@SergeiB

It seems important to gulp.src that the path passed by the plugin be absolute, so the src variable should contain the following value: path.resolve(path1, path2).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question