写gulp流的时候报错

查看:186
本文介绍了写gulp流的时候报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

在运行gulp的时候报错,错误如下:

[19:04:57] Finished 'default' after 7.38 μs
stream.js:74
      throw er; // Unhandled stream error in pipe.
      ^

Error: ENOENT: no such file or directory, stat 'D:\project\dist\js\index-6045b384e6.min.js'
    at Error (native)

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "D:\\Program\\nodejs\\node.exe" "D:\\Program\\nodejs\\node_modules\\npm\\bin\\npm-cli.           js" "run" "build"
npm ERR! node v4.5.0
npm ERR! npm  v2.15.9
npm ERR! code ELIFECYCLE
npm ERR! project@1.0.0 build: `gulp --gulpfile gulpfile-build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@1.0.0 build script 'gulp --gulpfile gulpfile-build.js'.
npm ERR! This is most likely a problem with the project package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     gulp --gulpfile gulpfile-build.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs project
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls project
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\project\npm-debug.log

gulpfile.js配置如下:

/*
* 打包上线时候用到的功能
* */
const gulp = require('gulp');
const rename = require('gulp-rename');              //重新命名生成的css和js文件
const sass = require('gulp-sass');                  //scss编译
const uglify = require('gulp-uglify');              //压缩js
const clean = require('gulp-clean');                //清空文件夹里所有的文件
const rev = require('gulp-rev');                    //生成带有哈希值的文件名
const runSequence = require('run-sequence');              //
//const reCollector = require('gulp-rev-collector');  //gulp-rev的插件,用于在生成带哈希值的文件名后替换html中的引用
//每次打包时先清空原有的文件夹
gulp.task('clean',()=>{
    gulp.src(['dist','rev'],{read:false})                   //这里设置的dist表示删除dist文件夹及其下所有文件
        .pipe(clean());

});
//scss编译
gulp.task('css',['clean'],()=>{
    gulp.src('src/scss/*.scss')
        .pipe(sass({
            outputStyle:'compressed'                //编译并输出压缩过的文件
         }))
        .pipe(rename(function (path) {
            path.basename += '.min';
        }))
        .pipe(rev())                                //给css添加哈希值
        .pipe(gulp.dest('dist/css'))
        .pipe(rev.manifest())                       //给添加哈希值的文件添加到清单中
        .pipe(gulp.dest('rev/css'));
});
//压缩js
gulp.task('js',['clean'],()=>{
    gulp.src('src/js/*js')
        .pipe(uglify())
        .pipe(rename(function (path) {
            path.basename += '.min';
        }))
        .pipe(rev())                                //给js添加哈希值
        .pipe(gulp.dest('dist/js'))
        .pipe(rev.manifest())                       //给添加哈希值的文件添加到清单中
        .pipe(gulp.dest('rev/js'));
});
//移动html文件到dist文件夹
gulp.task('html',['clean'],()=>{
    gulp.src('src/*.html')
        .pipe(gulp.dest('dist'));
});
//进行打包上线
gulp.task('build',()=>{
    runSequence('clean',['css','js'],'html');
});
//设置为gulp的默认任务
gulp.task('default',['build']);

解决方案

使run-sequence同步执行任务,另外在其他task中,gulp.src前面必须加上return

gulp.task('build',()=>{
    runSequence('clean',['css','js','html']);
});
//进行打包上线
gulp.task('default','build');

这篇关于写gulp流的时候报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆