javascript - Gulp Copy content from one file to another file - Stack Overflow

I am trying to copy the content from one file to another. I am trying the following code but its throwi

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742414574a4439489.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信