gulp"没有这样的文件或目录"或"文件已存在"何时不单独运行任务

时间:2016-10-26 14:45:59

标签: node.js npm gulp

我的Gulp-Tasks导致问题但仅限于我不单独运行。如果我只是运行" gulp js" everthing工作正常,如果我运行" gulp css" &# 34; gulp clean"

但如果我运行" npm start"

"start": "gulp npm-start && tsc && lite-server && concurrently \"tsc -w\""

任务:npm-start

gulp.task('npm-start', ['clean-dist', 'build-dev', 'watch']);

结果

  

events.js:141         扔掉//未处理的错误'事件         ^

     

错误:EEXIST:文件已经存在,mkdir   ' C:\开发\ MyProject的\研发\ myproject的应用程序的UI \程序\ SRC \ CSS'       在错误(本机)

OR

  

错误:EEXIST:文件已经存在,mkdir   ' C:\开发\ MyProject的\研发\ myproject的应用程序的UI \程序\ SRC \ CSS \ main.css的'       在错误(本机)

同时: 如果一切都能正常工作,我会为我创建以下三个目录:

  • 的src / HTML
  • 的src / CSS
  • SRC / JS

我经常遇到并非所有任务都被执行(但终端中没有错误信息)。例如,只有src / html /和src / css /,但不是src / js /。有时src / js和src / css在那里,但缺少src / html。它根本无法正常工作..

我的gulpfile.js

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    minifyCss = require('gulp-clean-css'),
    minifyJs = require('gulp-minify'),
    minifyHtml = require('gulp-minify-html'),
    clean = require('gulp-clean'),
    watch = require('gulp-watch'),
    gnf = require('gulp-npm-files');



/* compiles & prepares all sources tu run the app in npm lite server */
gulp.task('build-dev', [
    'clean',
    'css',
    'html',
    'js'
    //'ts' typescript will be compiled by "npm tsc" already :)
]);

gulp.task('npm-start', ['clean-dist', 'build-dev']);

/* builds everything and copies it to the dist-directory; removes previously dist directory */
gulp.task('build-release', ['build-dev', 'clean-dist'], function() {
    // index.html nach build/ kopieren
    gulp.src('index.html').pipe(gulp.dest('dist'));;

    // Copy (non-dev)dependencies to dist/node_modules/
    gulp.src(gnf(), {base:'./'}).pipe(gulp.dest('dist/node_modules/'));

    // copy compiled typescript files
    gulp.src('./app/**/*.js').pipe(gulp.dest('dist/app'));
    gulp.src('./app/**/*.js.map').pipe(gulp.dest('dist/app'));

    // copy css, html and js
    gulp.src('./app/src/**').pipe(gulp.dest('dist/app/'));
});



/* compiles SCSS to CSS, minifies it and puts it into the right directory */
// from:  uncompiled-src/scss/**.scss
// to:    app/src/css/**.css
gulp.task('css', function() {
    gulp.src('uncompiled-src/scss/**.scss')
        // .on('error', sass.logError)
        // --> verhindert, dass sass abstürtzt/beendet wird wenn mal eine Datei nicht übersetzt werden kann
        // --> nervig beim entwickeln, da so ständig der watch-Prozess endet
        .pipe(sass().on('error', sass.logError))
        .pipe(minifyCss())
        .pipe(gulp.dest('app/src/css'));
});



/* minifies JS and puts it into the right directory */
// from:  uncompiled-src/js/*.js
// to:    app/src/js/**.js
gulp.task('js', function() {
    gulp.src('uncompiled-src/js/**.js')
        .pipe(minifyJs({
            noSource: true,
            ext:{
                /*src:'-debug.js', not necessary cause noSource is set to true*/
                min:'.min.js'
            }
        }))
        .pipe(gulp.dest('app/src/js'));
});



/* compiles HTML puts it into the right directory */
// from:  uncompiled-src/html/**.html
// to:    app/src/html/**.html
gulp.task('html', function() {
    gulp.src('uncompiled-src/html/**.html')
        .pipe(minifyHtml())
        .pipe(gulp.dest('app/src/html'));
});



/* removes compiled sources and compiled typescript files */
// from:  app/**
gulp.task('clean', function() {
    gulp.src('app/**/*.js')
        .pipe(clean());
    gulp.src('app/**/*.js.map')
        .pipe(clean());
    gulp.src('app/src/*')
        .pipe(clean());
});



/* removes compiled previously dist directory */
// must be called beforce "tsc" (@see npm script "start")
// because otherwise tsc tries to compile ts-files in dist/node_modules/
gulp.task('clean-dist', function() {
    gulp.src('dist/')
        .pipe(clean());
});



// Rerun the task when a file changes
gulp.task('watch', function() {
    gulp.watch('uncompiled-src/html/*.html', ['html']);
    gulp.watch('uncompiled-src/js/*.js', ['js']);
    gulp.watch('uncompiled-src/scss/*.scss', ['css']);
});

我更新了gulpfile,我添加了return语句。但我仍然遇到了我的" js"任务。如果我擦除src /文件夹并启动应用程序一切正常,所有任务都会正确执行。如果我重新运行应用程序,我的clean-tasks将被执行,之后会有目录src / html和src / css,但src / js为空。但为什么呢?

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    minifyCss = require('gulp-clean-css'),
    minifyJs = require('gulp-minify'),
    minifyHtml = require('gulp-minify-html'),
    clean = require('gulp-clean'),
    watch = require('gulp-watch'),
    gnf = require('gulp-npm-files');



/* compiles & prepares all sources tu run the app in npm lite server */
gulp.task('build-dev', [
    'clean',
    'css',
    'html',
    'js'
    //'ts' typescript will be compiled by "npm tsc" already :)
]);

// can't run watch-tasks here because it would block the terminal
// therefore I call it with (npm start) concurrently \"gulp watch\"
gulp.task('npm-start', ['clean-dist', 'build-dev']);

/* builds everything and copies it to the dist-directory; removes previously dist directory */
gulp.task('build-release', ['build-dev', 'clean-dist'], function() {
    // index.html nach build/ kopieren
    gulp.src('index.html').pipe(gulp.dest('dist'));

    // Copy (non-dev)dependencies to dist/node_modules/
    gulp.src(gnf(), {base:'./'}).pipe(gulp.dest('dist/node_modules/'));

    // copy compiled typescript files
    gulp.src('./app/**/*.js').pipe(gulp.dest('dist/app'));
    gulp.src('./app/**/*.js.map').pipe(gulp.dest('dist/app'));

    // copy css, html and js
    gulp.src('./app/src/**').pipe(gulp.dest('dist/app/'));
});



/* compiles SCSS to CSS, minifies it and puts it into the right directory */
// from:  uncompiled-src/scss/**.scss
// to:    app/src/css/**.css
gulp.task('css', function() {
    return gulp.src('uncompiled-src/scss/**.scss')
        // .on('error', sass.logError)
        // --> verhindert, dass sass abstürtzt/beendet wird wenn mal eine Datei nicht übersetzt werden kann
        // --> nervig beim entwickeln, da so ständig der watch-Prozess endet
        .pipe(sass().on('error', sass.logError))
        .pipe(minifyCss())
        .pipe(gulp.dest('app/src/css'));
});



/* minifies JS and puts it into the right directory */
// from:  uncompiled-src/js/*.js
// to:    app/src/js/**.js
gulp.task('js', function() {
    return gulp.src('uncompiled-src/js/**.js')
        .pipe(minifyJs({
            noSource: true,
            ext:{
                /*src:'-debug.js', not necessary cause noSource is set to true*/
                min:'.min.js'
            }
        }))
        .pipe(gulp.dest('app/src/js'));
});



/* compiles HTML puts it into the right directory */
// from:  uncompiled-src/html/**.html
// to:    app/src/html/**.html
gulp.task('html', function() {
    return gulp.src('uncompiled-src/html/**.html')
        .pipe(minifyHtml())
        .pipe(gulp.dest('app/src/html'));
});



/* removes compiled sources and compiled typescript files */
// from:  app/**
gulp.task('clean', ['cleanTsJs', 'cleanTsJsMap', 'cleanAppSrc']);
gulp.task('cleanTsJs', function() {
    return gulp.src('app/**/*.js')
        .pipe(clean());
});
gulp.task('cleanTsJsMap', function() {
    return gulp.src('app/**/*.js')
        .pipe(clean());
});
gulp.task('cleanAppSrc', function() {
    return gulp.src('app/**/*.js')
        .pipe(clean());
});


/* removes compiled previously dist directory */
// must be called beforce "tsc" (@see npm script "start")
// because otherwise tsc tries to compile ts-files in dist/node_modules/
gulp.task('clean-dist', function() {
    return gulp.src('dist/')
        .pipe(clean());
});



// Rerun the task when a file changes
gulp.task('watch', ['js', 'html', 'css'], function() {
    gulp.watch('uncompiled-src/html/**.html', ['html']);
    gulp.watch('uncompiled-src/js/**.js', ['js']);
    gulp.watch('uncompiled-src/scss/**.scss', ['css']);
});

0 个答案:

没有答案