简体   繁体   English

“gulp-jade”不工作或将 jade 编译为 html

[英]'gulp-jade' not working or compiling jade to html

So I'm working on this project, and I'm using gulp.所以我正在做这个项目,我正在使用 gulp。 I need it to be able to compile the jade that I write (in the _jadefiles folder) and output them as .html into the _includes folder of my project.我需要它能够编译我编写的 jade(在 _jadefiles 文件夹中)并将它们作为 .html 输出到我的项目的 _includes 文件夹中。

The things I'm currently compiling and running with gulp are: - BrowserSync - Sass (Scss, technically.) - Autoprefixer - Something called Child Process (I started with a 'kit on github' called jekyll-gulp-sass-browser-sync ) - And Obviously Jade.我目前正在编制,一饮而尽运行的事情是: - BrowserSync -萨斯(SCSS,技术上) - Autoprefixer -一种叫子进程(我开始用“在github套件”称为哲基尔一饮而尽-萨斯浏览器同步) - 显然是玉。

Note: I'm also using Jekyll, however, that hopefully shouldn't matter.注意:我也在使用 Jekyll,但是,希望这无关紧要。

I'm following a video by DevTips, called Design+Code Hour 4.1我正在关注 DevTips 的视频,名为Design+Code Hour 4.1

Here's his current code:这是他当前的代码:

var gulp        = require('gulp');
var browserSync = require('browser-sync');
var sass        = require('gulp-sass');
var prefix      = require('gulp-autoprefixer');
var cp          = require('child_process');
var jade        = require('gulp-jade');

var messages = {
    jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};




/**
 * Build the Jekyll Site
 */
gulp.task('jekyll-build', function (done) {
    browserSync.notify(messages.jekyllBuild);
    return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
        .on('close', done);
});




/**
 * Rebuild Jekyll & do page reload
 */
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
    browserSync.reload();
});




/**
 * Wait for jekyll-build, then launch the Server
 */
gulp.task('browser-sync', ['sass', 'jekyll-build'], function() {
    browserSync({
        server: {
            baseDir: '_site'
        },
        notify: false
    });
});




/**
 * Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
 */
gulp.task('sass', function () {
    return gulp.src('assets/css/main.scss')
        .pipe(sass({
            includePaths: ['css'],
            onError: browserSync.notify
        }))
        .pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
        .pipe(gulp.dest('_site/assets/css'))
        .pipe(browserSync.reload({stream:true}))
        .pipe(gulp.dest('assets/css'));
});

His jade gulp stuff:他的玉吞东西:

/*
* I'm trying to gulp stuff, too. - 
*/

gulp.task('jade', function(){
  return gulp.src('_jadefiles/*.jade')
  .pipe(jade())
  .pipe(gulp.dest('_includes'));
});


/**
 * Watch scss files for changes & recompile
 * Watch html/md files, run jekyll & reload BrowserSync
 */
gulp.task('watch', function () {
    gulp.watch('assets/css/**', ['sass']);
    gulp.watch(['index.html', '_layouts/*.html', '_includes/*'], ['jekyll-rebuild']);
    gulp.watch('_jadefiles/*.jade', ['jade']);
});




/**
 * Default task, running just `gulp` will compile the sass,
 * compile the jekyll site, launch BrowserSync & watch files.
 */
gulp.task('default', ['browser-sync', 'watch']);

Everything else is working fine, exept this.其他一切正常,除了这个。

A bit late but hope it might help somebody who looks for a similar answer, I almost went crazy trying to figure out this for myself.有点晚了,但希望它可以帮助寻找类似答案的人,我几乎发疯了,试图为自己解决这个问题。

This sounds a little silly, but after having a similar problem (jade-gulp runs with no errors but not outputting index.html) and searching throughout the web for an answer with no luck, I realized I just had a syntax mistake in my .jade file (extra space character), so it would not compile to anything.这听起来有点傻,但是在遇到类似的问题(jade-gulp 运行没有错误但没有输出 index.html)并在整个网络上搜索没有运气的答案之后,我意识到我的 . jade 文件(额外的空格字符),所以它不会编译成任何东西。

try commenting out the entire content of your .jade file and then try to parse a very simple line (eg h1 hello) with gulp-jade.尝试注释掉 .jade 文件的全部内容,然后尝试使用 gulp-jade 解析一个非常简单的行(例如 h1 hello)。 check if it works, if it does, start debugging your code.检查它是否有效,如果有效,则开始调试您的代码。 Alternatively you can create a new .jade file with a simple code instead of commenting out the original file.或者,您可以使用简单的代码创建一个新的 .jade 文件,而不是注释掉原始文件。

Hope it helps!希望能帮助到你!

can you expand on any errors your seeing?你能扩展你看到的任何错误吗?

Does gulp jade run on its own - ie standalone - or is it just within your watch that it's not running? gulp jade是独立运行 - 即独立运行 - 还是只是在您的手表中不运行?

My gut feeling is there's more likely to be an error in your jade markup ( or pug as we need to start calling it )我的直觉是您的玉标记(或我们需要开始调用它的哈巴狗)中更有可能出现错误

Can you post any of that ?你能发一下吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM