pretty的问题:在将Jade编译为HTML时在Gulp中为true

时间:2014-12-21 03:29:15

标签: pug sublimetext gulp

问题

我一直在尝试使用pretty:true,我在gulpfile.js中的Jade documentation中提到了编译HTML的扩展/漂亮版本,但我得到了一个语法错误。

错误

/Users/andrewnguyen/Desktop/Websites/ryersonquidditch/gulpfile.js:33
      pretty: 'true'
      ^^^^^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Liftoff.handleArguments (/usr/local/lib/node_modules/gulp/bin/gulp.js:116:3)
    at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:159:12)
    at module.exports (/usr/local/lib/node_modules/gulp/node_modules/liftoff/node_modules/flagged-respawn/index.js:17:3)
    at Liftoff.launch (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:152:5)

gulpfile.js

// Include Gulp
var gulp = require('gulp'); 

// All of your plugins
var autoprefixer = require('gulp-autoprefixer');
var cache = require('gulp-cache');
var concat = require('gulp-concat');
var imagemin = require('gulp-imagemin');
var jade = require('gulp-jade');
var jshint = require('gulp-jshint');
var livereload = require('gulp-livereload');
var minify = require('gulp-minify-css');
var notify = require('gulp-notify');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');

// Watch files for changes
gulp.task('watch', function() {
    gulp.watch('assets/js/*.js', ['scripts', 'style']);
    gulp.watch('assets/css/*.scss', ['styles']);
    gulp.watch('assets/jade/*.jade', ['templates']);
});

// Compile HTML from Jade
gulp.task('templates', function() {
  var YOUR_LOCALS = {};

  gulp.src('*.jade')
    .pipe(jade({
      locals: YOUR_LOCALS
      pretty: true
    }))
    .pipe(gulp.dest('assets/jade'))
    .pipe(notify({ message: 'Your Jade file has been molded into HTML.' }))
});

// Compile CSS, Autoprefix and Minify
gulp.task('styles', function() {
  return gulp.src('assets/css/style.scss')
    .pipe(sass({ style: 'expanded' }))
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
    .pipe(gulp.dest('assets/css'))
    .pipe(rename({suffix: '.min'}))
    .pipe(minify())
    .pipe(gulp.dest('assets/css'))
    .pipe(notify({ message: 'Your Sass file has been compiled, auto-prefixed and minified.' }));
});

// Lint, Concatenate and Minify JavaScript
gulp.task('scripts', function() {
  return gulp.src('assets/js/**/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    .pipe(concat('scripts.js'))
    .pipe(gulp.dest('assets/js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('assets/js'))
    .pipe(notify({ message: 'Your JavaScript files have been linted, concatenated and minified.' }));
});

// Compress Images
gulp.task('images', function() {
  return gulp.src('assets/img/**/*')
    .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
    .pipe(gulp.dest('/assets/img'))
    .pipe(notify({ message: 'Your image files have been folded into an origami paper crane.' }));
});

// Default Task
gulp.task('default', function() {
    gulp.start('images', 'scripts', 'styles', 'templates', 'watch');
});

1 个答案:

答案 0 :(得分:3)

您忘记了json对象中的,

pipe(jade({
  locals: YOUR_LOCALS,
  pretty: true
}))