新增 gulp 任務

在你的離子應用程式的根目錄中,有一個 gulpfile.js 檔案。在編輯器中開啟它並貼上以下 gulp 任務:

gulp.task('lint', function() {
    return gulp.src(['./www/js/**/*.js']) 
        .pipe(jshint('.jshintrc'))
        .pipe(jshint.reporter('jshint-stylish')) 
        .pipe(jshint.reporter('fail'))
});

這會在’www’資料夾中查詢名為’js’的資料夾。如果你有包含 JavaScript 檔案的其他資料夾,也請新增它們。例如,還可以新增一個名為 views 的資料夾:

gulp.task('lint', function() {
    return gulp.src(['./www/js/**/*.js','./www/views/**/*.js'])
        .pipe(jshint('.jshintrc'))
        .pipe(jshint.reporter('jshint-stylish')) 
        .pipe(jshint.reporter('fail'))
});

說明:

1) /**/*.js - This syntax means to look at all the js files in the subfolders too
2) .jshintrc - This is a configuration file that we will create in the next example.