Gulp错误=文件已存在,

时间:2016-03-17 18:54:33

标签: node.js npm gulp

你可以帮助我吗? 我无法弄清楚最近两天在我的gulpfile中出了什么问题。
谷歌无法帮助我...
我有简单的门,gulpfile ...
https://github.com/di3orlive/cleanProject

我和我的朋友们有同样的错误,但是一个人在linux避风港 我们都使用win10
节点5.9.0
npm 3.7.3
gulp 3.9.1

var gulp = require('gulp'),
    del = require('del'),
    wiredep = require('wiredep').stream,
    gutil = require('gulp-util'),
    plumber = require('gulp-plumber'),
    rename = require('gulp-rename'),
    sass = require('gulp-sass'),
    concat = require('gulp-concat'),
    webserver = require('gulp-webserver'),
    notify = require("gulp-notify"),
    imageop = require('gulp-image-optimization'),
    htmlmin = require('gulp-htmlmin'),
    minify = require('gulp-minify'),
    postcss = require('gulp-postcss'),
    autoprefixer = require('autoprefixer'),
    cssnano = require('cssnano');


gulp.task('clean', function () {
    del.sync(['./www/**']);
});


gulp.task('build', ['clean'], function (){
////COPY_REST///////////////////////////////////////////////////////////////////////////////////////////////////////////
    gulp.src(['!./src/scss/**', '!./src/js/**', '!./src/**/*.html', './src/**'])
        .pipe(gulp.dest('./www/'));
////BOWER///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    gulp.src('./src/**/*.html')
        .pipe(plumber({errorHandler: reportError}))
        .pipe(wiredep({directory: './src/bower/'}))
        .pipe(gulp.dest('./src/'));
////STYLE///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    gulp.src(['./src/scss/all.scss'])
        .pipe(plumber({errorHandler: reportError}))
        .pipe(sass())
        .pipe(concat('main.css'))
        .pipe(gulp.dest('./www/css/'))
        .pipe(postcss([
            autoprefixer,cssnano
        ]))
        .pipe(rename({suffix: '-min'}))
        .pipe(gulp.dest('./www/css/'));
////JS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    gulp.src(['./src/js/main.js', './src/js/**/*.js'])
        .pipe(plumber({errorHandler: reportError}))
        .pipe(concat('main.js'))
        .pipe(gulp.dest('./www/js/'))
        .pipe(minify())
        .pipe(gulp.dest('./www/js/'));
////HTML_MIN////////////////////////////////////////////////////////////////////////////////////////////////////////////
    gulp.src('./src/**/*.html')
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('./www/'));
});


gulp.task('imin', function() {
    gulp.src('./src/i/**/*.*')
        .pipe(imageop({
            optimizationLevel: 5,
            progressive: true,
            interlaced: true
        })).pipe(gulp.dest('./src/imin/')).on('end').on('error');
});


gulp.task('webserver', function () {
    gulp.src('./www/')
        .pipe(webserver({
                livereload: true,
                port: 11111,
                open: 'index.html',
                directoryListing: {
                    enable: true,
                    path: './www/'
                }
            })
        )
});


gulp.task('release', function () {
    var number = gutil.env.number;
    //gulp release --number 0.1
    if (fs.existsSync('./releae/' + number)){
        return console.error('Number ' + number + ' already exists')
    }
    console.log('Making release ' + number + ' ');
    gulp.src('./www/**/*.*')
        .pipe(gulp.dest("./releases/" + number + '/'));
});


gulp.task('default', function () {
    gulp.run(['clean', 'build', 'webserver']);

    gulp.watch('./src/**/*.*', ['build']);
});

//======================================================================================================================

var reportError = function (error) {
    notify({
        title: 'Error',
        message: 'Check the console.'
    }).write(error);

    console.log(error.toString());

    this.emit('end');
};

和包

{
  "name": "di3orlive",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "di3orlive",
  "license": "ISC",
  "devDependencies": {
    "autoprefixer": "^6.3.3",
    "cssnano": "^3.5.2",
    "del": "^2.2.0",
    "gulp": "^3.9.1",
    "gulp-concat": "^2.6.0",
    "gulp-htmlmin": "^1.3.0",
    "gulp-image-optimization": "^0.1.3",
    "gulp-minify": "0.0.5",
    "gulp-notify": "^2.2.0",
    "gulp-plumber": "^1.1.0",
    "gulp-postcss": "^6.1.0",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^2.2.0",
    "gulp-util": "^3.0.7",
    "gulp-webserver": "^0.9.1",
    "wiredep": "^3.0.0"
  }
}

错误

D:\WORK\OPEN\DI3>gulp
[21:08:52] Using gulpfile D:\WORK\OPEN\DI3\gulpfile.js
[21:08:52] Starting 'default'...
gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.
[21:08:52] Starting 'clean'...
[21:08:52] Finished 'clean' after 2.61 ms
[21:08:52] Starting 'build'...
[21:08:53] Finished 'build' after 19 ms
[21:08:53] Starting 'webserver'...
[21:08:53] Webserver started at http://localhost:11111
[21:08:53] Finished 'webserver' after 7.91 ms
[21:08:53] Finished 'default' after 127 ms
[21:08:53] gulp-notify: [Error] Check the console.
TypeError: must start with number, buffer, array or string
[21:08:53] gulp-notify: [Error] Check the console.
Error: write after end
[21:08:53] Starting 'clean'...
[21:08:53] Finished 'clean' after 13 ms
[21:08:53] Starting 'build'...
[21:08:53] Finished 'build' after 4.09 ms
[21:08:53] gulp-notify: [Error] Check the console.
Error: ENOENT: no such file or directory, chmod 'D:\WORK\OPEN\DI3\www\js\main.js'
events.js:154
throw er; // Unhandled 'error' event
^

Error: EEXIST: file already exists, mkdir 'D:\WORK\OPEN\DI3\www'
at Error (native)

1 个答案:

答案 0 :(得分:0)

在异步执行任务时似乎存在问题......以下是我推荐的一些变化......这可能会解决问题。

dude.say_something = function(whats::AbstractString...)
    length(whats) < 2 || error("too many arguments")
    what = isempty(whats) ? "hi" : whats[1]
    print(what)
end

但是这样一来,每次发生变化时都会清理你的构建,这需要花费时间,具体取决于你的项目。

更好的方法是使用//This task is fine..having dependency of clean gulp.task('build', ['clean'], function (){ ... }) //execute build as dependency for webserver task. gulp.task('webserver',['build'], function () { ... }) // gulp.task('default',['webserver'], function () { //you can get rid of the run task now..as all task are in async gulp.watch('./src/**/*.*', ['build']); }); 。见this

编辑:

gulp-run-sequence

还有一件事......我看到你粘贴的图片。为gulp.task('webserver', function () { gulp.src('./www/') .pipe(webserver({ host:'127.0.0.1', //if you want, else localhost will be used by default livereload: true, port: 11111, open: true, //or any address that you might have configured for localhost directoryListing: false, //this should be false, you want serve a page rather that showing a folder structure fallback:'index.html' //this is recommended for one page applications }) ) }); 创建一个单独的任务,并将其作为run-sequence任务的依赖项传递。如果有问题或任何其他错误发生,请告诉我。

相关问题