I have a problem when I try to overwrite a file with gulp. To make you understand my problem here's an example of what I am trying to do: My project file path:
当我尝试用gulp覆盖文件时遇到问题。为了让你理解我的问题这里是我想要做的一个例子:我的项目文件路径:
- Project
|- clients
|- clientBase
|- JS
|- jsexample.js
|- jsexample2.js
|- CSS
|- HTML
|- client1
|- JS
|- jsexample2.js
|-dist
- Copy the base source to
dist
. - Copy the custom client source and overwrite what's in the dist folder.
将基础源复制到dist。
复制自定义客户端源并覆盖dist文件夹中的内容。
What am I doing
const args = require('yargs').argv;
const src = {
base: './Project/clients/clientBase',
client: `./Project/clients/${args.client}`,
};
const dist = './Project/dist';
const runSequence = require('run-sequence');
gulp.task('copy:base', function(){
return gulp
.src(`${src.base}/**/*`)
.pipe(gulp.dest(dist))
});
gulp.task('copy:client', function(){
return gulp
.src(`${src.client}/**/*`)
.pipe(gulp.dest(dist))
});
gulp.task('copy', function(){
if (args.client) {
runSequence('copy:base', 'copy:client');
} else {
runSequence('copy:base');
}
});
The actual problem
The problem is that the dist files are not being overwritten by the copy:client
task.
问题是dist文件没有被copy:client任务覆盖。
What I've checked already
I've checked the file path and the content inside the files. The argument client
is being passed to, so this task is being executed.
我检查了文件路径和文件内的内容。正在传递参数客户端,因此正在执行此任务。
2 个解决方案
#1
0
dist needs to be quoted:
dist需要引用:
.pipe(gulp.dest('dist'))
You may also need to change the path, depending on where you're running gulp from
您可能还需要更改路径,具体取决于您从哪里运行
#2
0
After some more research, I noticed that in my task sequence chain in the default task
, there was another task copying again the base code, without any logging.
经过一些研究,我注意到在默认任务的任务序列链中,有另一个任务再次复制基本代码,没有任何记录。
#1
0
dist needs to be quoted:
dist需要引用:
.pipe(gulp.dest('dist'))
You may also need to change the path, depending on where you're running gulp from
您可能还需要更改路径,具体取决于您从哪里运行
#2
0
After some more research, I noticed that in my task sequence chain in the default task
, there was another task copying again the base code, without any logging.
经过一些研究,我注意到在默认任务的任务序列链中,有另一个任务再次复制基本代码,没有任何记录。