admin管理员组

文章数量:1336632

I am trying to copy the content from one file to another. I am trying the following code but its throwing me an error.

gulp
    .src('core/core.config.local.tpl.js')
    .pipe(gulp.dest(core/core.config.js));

Error: EEXIST: file already exists, mkdir 'C:\Users\krish\Documents\test\app\core\core.config.js' at Error (native)

Is there any other process that I could use to copy content?

I am trying to copy the content from one file to another. I am trying the following code but its throwing me an error.

gulp
    .src('core/core.config.local.tpl.js')
    .pipe(gulp.dest(core/core.config.js));

Error: EEXIST: file already exists, mkdir 'C:\Users\krish\Documents\test\app\core\core.config.js' at Error (native)

Is there any other process that I could use to copy content?

Share Improve this question asked Feb 27, 2016 at 14:43 KrishhKrishh 4,2316 gold badges43 silver badges52 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

gulp.dest expects a directory as an argument. All files are written to this destination directory. If the directory doesn't exist yet, gulp tries to create it.

In your case gulp.dest tries to create a directory core/core.config.js, but fails since a regular file with the same name already exists.

If your goal is to have the regular file at core/core.config.js be overwritten with the contents of core/core.config.local.tpl.js on every build, you can do it like this:

var gulp = require('gulp');
var rename = require('gulp-rename');

gulp.task('default', function() {
  gulp.src('core/core.config.local.tpl.js')
    .pipe(rename({ basename: 'core.config'}))
    .pipe(gulp.dest('core'));
});

I think you were missing the quotes only when entering the the question here, right?

gulp.dest() expects a folder to copy all the files in the stream, so you cannot use a single file name here (As the error says: "mkdir failed"). See: https://github./gulpjs/gulp/blob/master/docs/API.md#gulpdestpath-options

When you do your gulp.src() you can set a base path to build the relative path from and so gulp can copy your single file to the given output folder. See: https://github./gulpjs/gulp/blob/master/docs/API.md#optionsbase

As you also want to rename the file, you need something like gulp-rename: https://www.npmjs./package/gulp-rename

本文标签: javascriptGulp Copy content from one file to another fileStack Overflow