11

に問題がありgulpます。私は ととgulp-watch一緒に走ります。すべてが完璧に動作しています。gulp-lessgulp-clean

編集somefile.lessして保存すると、セミコロンがないか、誤って末尾;sgulp-less. 修正後もgulp-watchファイルの監視を続けますが、gulp-less起動せず、コンパイルもしません。ターミナルで停止gulpして再度実行すると、すべてが正常に戻ります。

これが私のものgulpfile.jsです:

var gulp = require('gulp');
var clean = require('gulp-clean');
var gutil = require('gulp-util');
var less = require('gulp-less');
var watch = require('gulp-watch');
var path = require('path');

gulp.task('clean', function() {
    return gulp.src('src/main/webapp/styles/build', {read: false})
   .pipe(clean().on('error', gutil.log))
});

gulp.task('less', function() {
    return gulp.src(['src/main/webapp/styles/main.less'], {base: 'src/main/webapp/styles/'})
    .pipe(less().on('error', gutil.log))
    .pipe(gulp.dest('src/main/webapp/styles/build'))
    .on('error', gutil.log);
});

gulp.task('watch', function() {
    watch('src/main/webapp/styles/**/*.{less, css}', function() {
        gulp.start('less')
        .on('error', gutil.log);
    })
});

gulp.task('default', ['clean'], function() {
    gulp.start(['less', 'watch'])
    .on('error', gutil.log);
});

そして、ここに私のものがありますdevDependencies

"devDependencies": {
    "gulp": "^3.8.10",
    "gulp-clean": "^0.3.1",
    "gulp-less": "^2.0.1",
    "gulp-util": "^3.0.2",
    "gulp-watch": "^3.0.0"
}

最後に、コンソールのメッセージは次のとおりです。

[10:21:03] imports/productSearchPage.less was changed
[10:21:03] Starting 'less'...
[10:21:03] { [Error: Unrecognised input. Possibly missing something in file /src/main/webapp/styles/imports/productSearchPage.less line no. 1008]
  type: 'Parse',
  filename: '/src/main/webapp/styles/imports/productSearchPage.less',
  index: 19127,
  line: 1008,
  callLine: NaN,
  callExtract: undefined,
  column: 0,
  extract: [ '', '', undefined ],
  message: 'Unrecognised input. Possibly missing something in file /src/main/webapp/styles/imports/productSearchPage.less line no. 1008',
  stack: undefined,
  lineNumber: 1008,
  fileName: '/src/main/webapp/styles/imports/productSearchPage.less',
  name: 'Error',
  showStack: false,
  showProperties: true,
  plugin: 'gulp-less',
  __safety: { toString: [Function] } }
[10:21:04] imports/productSearchPage.less was changed
[10:21:08] imports/productSearchPage.less was changed
^C

タスクの何が問題なのか教えてください。エラーが削除された後、再起動せずにgulp-watchタスクを実行できるようにしてください。gulp-lessgulp

編集:私の編集したgulp-lessタスク

gulp.task('less', function() {
    return gulp.src(['src/main/webapp/styles/main.less'], {base: 'src/main/webapp/styles/'})
    .pipe(less().on('error', gutil.log))
    .pipe(gulp.dest('src/main/webapp/styles/build'))
    .on('error', function(err) {
        gutil.log(err);
        this.emit('end');
    });
});
4

4 に答える 4

22

それは今動作します!これが私の最終的なgulp-less作業タスクです。

gulp.task('less', function() {
    return gulp.src(['src/main/webapp/styles/main.less'], {base: 'src/main/webapp/styles/'})
    .pipe(less().on('error', function(err){
        gutil.log(err);
        this.emit('end');
    }))
    .pipe(gulp.dest('src/main/webapp/styles/build'))
});

問題はLESS、タスクにエラーが発生した場合でも、宛先ファイルをビルドして続行することでした。その上に、エラー ログ関数とemit('end')へのコールバックを配置しましたgulp.dest

のコールバックがless()エラー ログであり、emit('end')すべてが完全に機能する場合。

于 2015-01-28T14:24:40.057 に答える
2

エラーキャッチには常にgulp-plumberを使用しています。非常に簡単に機能し、エラーをコンソールに記録します。

例:

gulp.task('less', function() {
    return gulp.src(['src/main/webapp/styles/main.less'], {base: 'src/main/webapp/styles/'})
    .pipe(plumber())
    .pipe(less().on('error', gutil.log))
    .pipe(gulp.dest('src/main/webapp/styles/build'))
    .on('error', function(err) {
        gutil.log(err);
        this.emit('end');
    });
});
于 2015-01-27T11:28:38.467 に答える
0

私は自分の個人的なプロジェクトのためにこれを設定しました。Gulp docsによると、次のものを使用できますgulp.watch

gulp.task('watch', function() {
    gulp.watch('src/main/webapp/styles/**/*.{less, css}', ['less'])
        .on('error', gutil.log);
});

編集:これで問題が解決しない場合は、lessタスクを次のように変更してください。

gulp.task('less', function() {
    return gulp.src(['src/main/webapp/styles/main.less'], {base: 'src/main/webapp/styles/'})
    .pipe(less())
    .on('error', function (err) {
        gutil.log(err);
        this.emit('end');
    })
    .pipe(gulp.dest('src/main/webapp/styles/build'))
    .on('error', gutil.log);
});

このコメントから適応。

于 2015-01-27T08:59:35.613 に答える