2016-03-15 76 views
0

我已經將gulp-jade添加到標準配置中並添加了一個'templates'任務,用於'服務'和'構建'任務。 當我運行構建,一切看起來不錯,但生成的索引文件是空的。 我不知道如何解決這個問題,請看看我的大文件,也許這是一個微不足道的問題,但對我來說非常重要。謝謝。當運行generator-gulp-webapp(含gulp-jade)的'build'任務時產生一個空index.html

// generated on 2016-03-14 using generator-gulp-webapp 1.1.1 
import gulp from 'gulp'; 
import gulpLoadPlugins from 'gulp-load-plugins'; 
import jade from 'gulp-jade'; 
import browserSync from 'browser-sync'; 
import del from 'del'; 
import {stream as wiredep} from 'wiredep'; 

const $ = gulpLoadPlugins(); 
const reload = browserSync.reload; 

gulp.task('templates', function() { 
    var locals = 'app/jade'; 

    gulp.src('app/jade/*.jade') 
    .pipe(jade({ 
     locals: locals 
    })) 
    .pipe(gulp.dest('app/')) 
}); 

gulp.task('styles',() => { 
    return gulp.src('app/styles/*.scss') 
    .pipe($.plumber()) 
    .pipe($.sourcemaps.init()) 
    .pipe($.sass.sync({ 
     outputStyle: 'expanded', 
     precision: 10, 
     includePaths: ['.'] 
    }).on('error', $.sass.logError)) 
    .pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']})) 
    .pipe($.sourcemaps.write()) 
    .pipe(gulp.dest('.tmp/styles')) 
    .pipe(reload({stream: true})); 
}); 

gulp.task('scripts',() => { 
    return gulp.src('app/scripts/**/*.js') 
    .pipe($.plumber()) 
    .pipe($.sourcemaps.init()) 
    .pipe($.babel()) 
    .pipe($.sourcemaps.write('.')) 
    .pipe(gulp.dest('.tmp/scripts')) 
    .pipe(reload({stream: true})); 
}); 

function lint(files, options) { 
    return() => { 
    return gulp.src(files) 
     .pipe(reload({stream: true, once: true})) 
     .pipe($.eslint(options)) 
     .pipe($.eslint.format()) 
     .pipe($.if(!browserSync.active, $.eslint.failAfterError())); 
    }; 
} 
const testLintOptions = { 
    env: { 
    mocha: true 
    } 
}; 

gulp.task('lint', lint('app/scripts/**/*.js')); 
gulp.task('lint:test', lint('test/spec/**/*.js', testLintOptions)); 

gulp.task('html', ['styles', 'scripts'],() => { 
    return gulp.src('app/*.html') 
    .pipe($.useref({searchPath: ['.tmp', 'app', '.']})) 
    .pipe($.if('*.js', $.uglify())) 
    .pipe($.if('*.css', $.cssnano())) 
    .pipe($.if('*.html', $.htmlmin({collapseWhitespace: true}))) 
    .pipe(gulp.dest('dist')); 
}); 

gulp.task('images',() => { 
    return gulp.src('app/images/**/*') 
    .pipe($.if($.if.isFile, $.cache($.imagemin({ 
     progressive: true, 
     interlaced: true, 
     // don't remove IDs from SVGs, they are often used 
     // as hooks for embedding and styling 
     svgoPlugins: [{cleanupIDs: false}] 
    })) 
    .on('error', function (err) { 
     console.log(err); 
     this.end(); 
    }))) 
    .pipe(gulp.dest('dist/images')); 
}); 

gulp.task('fonts',() => { 
    return gulp.src(require('main-bower-files')('**/*.{eot,svg,ttf,woff,woff2}', function (err) {}) 
    .concat('app/fonts/**/*')) 
    .pipe(gulp.dest('.tmp/fonts')) 
    .pipe(gulp.dest('dist/fonts')); 
}); 

gulp.task('extras',() => { 
    return gulp.src([ 
    'app/*.*', 
    '!app/*.html' 
    ], { 
    dot: true 
    }).pipe(gulp.dest('dist')); 
}); 

gulp.task('clean', del.bind(null, ['.tmp', 'dist'])); 

gulp.task('serve', ['templates','styles', 'scripts', 'fonts'],() => { 
    browserSync({ 
    notify: false, 
    port: 9000, 
    server: { 
     baseDir: ['.tmp', 'app'], 
     routes: { 
     '/bower_components': 'bower_components' 
     } 
    } 
    }); 

    gulp.watch([ 
    'app/*.html', 
    '.tmp/scripts/**/*.js', 
    'app/images/**/*', 
    '.tmp/fonts/**/*' 
    ]).on('change', reload); 


    gulp.watch('app/jade/**/*.jade', ['templates']); 
    gulp.watch('app/styles/**/*.scss', ['styles']); 
    gulp.watch('app/scripts/**/*.js', ['scripts']); 
    gulp.watch('app/fonts/**/*', ['fonts']); 
    gulp.watch('bower.json', ['wiredep', 'fonts']); 
}); 

gulp.task('serve:dist',() => { 
    browserSync({ 
    notify: false, 
    port: 9000, 
    server: { 
     baseDir: ['dist'] 
    } 
    }); 
}); 

gulp.task('serve:test', ['scripts'],() => { 
    browserSync({ 
    notify: false, 
    port: 9000, 
    ui: false, 
    server: { 
     baseDir: 'test', 
     routes: { 
     '/scripts': '.tmp/scripts', 
     '/bower_components': 'bower_components' 
     } 
    } 
    }); 

    gulp.watch('app/scripts/**/*.js', ['scripts']); 
    gulp.watch('test/spec/**/*.js').on('change', reload); 
    gulp.watch('test/spec/**/*.js', ['lint:test']); 
}); 

// inject bower components 
gulp.task('wiredep',() => { 
    gulp.src('app/styles/*.scss') 
    .pipe(wiredep({ 
     ignorePath: /^(\.\.\/)+/ 
    })) 
    .pipe(gulp.dest('app/styles')); 

    gulp.src('app/*.html') 
    .pipe(wiredep({ 
     exclude: ['bootstrap-sass'], 
     ignorePath: /^(\.\.\/)*\.\./ 
    })) 
    .pipe(gulp.dest('app')); 
}); 

gulp.task('build', ['lint','templates','html','images','fonts'],() => { 
    return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true})); 
}); 

gulp.task('default', ['clean'],() => { 
    gulp.start('build'); 
}); 

回答

0

locals變量應該是一個對象

gulp.task('templates', function() { 
    var locals = { 
    myValue: "myValue" 
    }; 

    gulp.src('app/jade/*.jade') 
    .pipe(jade({ 
     locals: locals 
    })) 
    .pipe(gulp.dest('app/')) 
}); 

我不能得到正是你正試圖在這裏做什麼,你想讀「應用程序/玉」文件夾多個當地人的文件?

相關問題