Gulp任务执行正常但文件未复制到指定路径的问题排查
Gulp文件复制任务无效果问题解决
原始测试代码
const gulp = require('gulp'); gulp.task('clone', function() { return gulp.src('TEST/index.html') .pipe(gulp.dest('public/')); });
目录结构
- Gulp/
- TEST/
- index.html
- public/(文件复制无结果)
- gulpfile.js
- TEST/
执行日志
C:\Users\alesh\OneDrive\Working stol[SuperSliv.biz][ItProger] Processing of the full stack by the developer\Gulp>cloning gulp
[21:25:32] Using gulpfile ~\OneDrive\Desktop[SuperSliv.biz ][ItProger] Loading the full stack of developer\Gulp\gulpfile.js
[21:25:32] Starting "cloning"...
[21:25:32] The "cloning" is completed after 11 ms
尝试的修改代码(存在语法错误)
const gulp = require('gulp'); gulp.task('clone', function() { return gulp.src(['TEST/index.html'], {base: 'TEST'} .pipe(gulp.dest('public/')); });
问题排查与解决
1. 任务名不匹配
代码中定义的任务名为clone,但你执行的命令是cloning gulp,实际运行的是不存在的cloning任务,这是任务看似执行却无效果的核心原因。
正确执行命令应为:
gulp clone
2. 修改代码存在语法错误
添加base参数时,gulp.src的参数列表缺失闭合括号,正确写法如下:
const gulp = require('gulp'); gulp.task('clone', function() { return gulp.src(['TEST/index.html'], {base: 'TEST'}) // 补上缺失的闭合括号 .pipe(gulp.dest('public/')); });
3. 路径验证
你的目录结构中,TEST/index.html是相对于gulpfile.js的正确路径,无需调整。执行正确命令后,文件会被复制到public/index.html;若想保留TEST目录结构,可将base设为.,最终文件会存到public/TEST/index.html。
内容的提问来源于stack exchange,提问作者Alexey
相关产品推荐
相关产品推荐

