【问题标题】:Gulp error = file already exists,Gulp 错误 = 文件已存在,
【发布时间】:2016-03-18 04:50:28
【问题描述】:

你能帮帮我吗
我无法弄清楚过去两天我的 gulpfile 出了什么问题。
谷歌帮不了我...
我有简单的门,gulpfile...
https://github.com/di3orlive/cleanProject

我和我的 2 个朋友有同样的错误,但 linux 上的一个人没有
我们都用win10
节点 5.9.0
npm 3.7.3
吞咽 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)

【问题讨论】:

  • 你遇到什么错误..?

标签: node.js npm gulp


【解决方案1】:

似乎在异步执行任务时出现了问题...这里有一些我会推荐的更改...这可能会解决问题。

//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']);
});

但是这样每次发生更改时都会清理您的构建,这需要时间取决于您的项目。

所以更好的方法是使用gulp-run-sequence。见this

编辑:

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 创建一个单独的任务并将其作为default 任务的依赖项传递。让我知道是否有效或发生任何其他错误。

【讨论】:

  • 添加新插件后也无济于事joxi.ru/12M79xXt4nZxnr
  • 这不起作用('!./src/scss/**', '!./src/js/**', '!./src/**/*.html ', './src/**' ) 也许我的系统有问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-17
  • 2019-09-10
  • 2017-10-03
  • 2014-06-29
  • 2016-05-20
  • 1970-01-01
  • 2023-03-07
相关资源
最近更新 更多