使用gulp.dest复制文件时出现文件损坏问题
问题:使用gulp.dest复制二进制文件(PNG、woff/woff2)时损坏
复制文件路径正确,但文件体积变大且无法正常使用:
- 图片文件中,
.svg无问题,.png损坏 - woff/woff2字体文件同样损坏
使用的包版本
"browser-sync": "^3.0.2", "del": "^7.1.0", "gulp": "^5.0.0", "gulp-autoprefixer": "^9.0.0", "gulp-clean-css": "^4.3.0", "gulp-cli": "^3.0.0", "gulp-prettier": "^6.0.0", "gulp-pug": "^5.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.1.4", "gulp-sass": "^5.1.0", "path": "^0.12.7", "pug": "^3.0.2", "sass": "^1.72.0"
gulpfile.mjs 内容
import gulp from "gulp"; import path from "./gulp/config/path.mjs"; import plugins from "./gulp/config/plugins.mjs"; global.app = { path: path, gulp: gulp, plugins: plugins, }; import copy from "./gulp/tasks/copy.mjs"; import reset from "./gulp/tasks/reset.mjs"; import pug from "./gulp/tasks/pug.mjs"; import server from "./gulp/tasks/server.mjs"; import scss from "./gulp/tasks/scss.mjs"; import image from "./gulp/tasks/image.mjs"; import js from "./gulp/tasks/js.mjs"; import format from "./gulp/tasks/format.mjs"; gulp.task("format", format); function watcher() { gulp.watch(path.watch.fonts, copy); gulp.watch(path.watch.pug, pug); gulp.watch(path.watch.scss, scss); gulp.watch(path.watch.img, image); gulp.watch(path.watch.js, js); } const mainTasks = gulp.parallel(copy, pug, scss, image, js); const dev = gulp.series(reset, mainTasks, gulp.parallel(watcher, server)); gulp.task("default", dev);
image.mjs 内容
const image = () => { return app.gulp .src(app.path.src.img) .pipe(app.gulp.dest(app.path.build.img)) .pipe(app.plugins.browsersync.stream()); }; export default image;
copy.mjs 内容
const copy = () => { return app.gulp .src(app.path.src.fonts) .pipe(app.gulp.dest(app.path.build.fonts)); }; export default copy;
已尝试的解决方案
- 使用
gulp-copy插件替代gulp.dest,无效 - 参考过GitHub上的类似问题,其中的解决方案不适用
内容的提问来源于stack exchange,提问作者Parbiska
相关产品推荐
相关产品推荐

