Grunt编译Jade文件 [英] Grunt compiling Jade files

查看:73
本文介绍了Grunt编译Jade文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置我的Gruntfile以将我所有的Jade文件编译为单独的HTML文件。例如,如果我有以下源文件夹:

 
└──模板
├─ ─first.jade
├──second.jade
└──third.jade

然后我期望 grunt jade 输出:

  build 
└──模板
├──first.html
├──second.html
└──third.html

这是我的Gruntfile,使用 grunt-contrib-jade

  module.exports = function(grunt){
grunt.initConfig({

jade:{
compile:{
选项:{
client:false,
pretty:true
},
files:[{
src:* .jade,
dest:build / templates /,
ext:html,
cwd:source / templates /
}]
}
},
});

grunt.loadNpmTasks(grunt-contrib-jade);
};

但是,当我运行jade命令时,出现以下错误:

 运行jade:compile(jade)任务
>>未找到源文件first.jade。
>>未找到源文件second.jade。
>>未找到源文件third.jade。

我做错了什么?

解决方案

完成上面的回答

  jade:{
compile:{
选项:{
client:false,
pretty:true
},
files:[{
cwd:app / views,
src:** / *。jade,
dest:build / templates,
展开:true,
ext:.html
}]






$ b因此,如果你的源代码结构如此:

  app 
└──views
└──main.jade
└──user
└──signup.jade
└──preferences.jade

grunt jade 会创建以下结构

  build 
└──templates
└── main.html
└──使用者
└──signup.html
└──preferences.html

编辑:
不赞成使用 grunt-contrib-jade 。您应该使用 grunt-contrib-pug 。这是完全一样的,但他们必须重命名玉到帕格!


I'm trying to configure my Gruntfile to compile all of my Jade files to individual HTML files. For example, if I have the following source folder:

source
└── templates
    ├── first.jade
    ├── second.jade
    └── third.jade

Then I would expect grunt jade to output:

build
└── templates
    ├── first.html
    ├── second.html
    └── third.html

Here's my Gruntfile using grunt-contrib-jade:

module.exports = function(grunt) {
    grunt.initConfig({

        jade: {
            compile: {
                options: {
                    client: false,
                    pretty: true
                },
                files: [ {
                  src: "*.jade",
                  dest: "build/templates/",
                  ext: "html",
                  cwd: "source/templates/"
                } ]
            }
        },
    });

    grunt.loadNpmTasks("grunt-contrib-jade");
};

However, when I run the jade command I get the following errors:

Running "jade:compile" (jade) task
>> Source file "first.jade" not found.
>> Source file "second.jade" not found.
>> Source file "third.jade" not found.

What am I doing wrong?

解决方案

To complete the above answer

    jade: {
        compile: {
            options: {
                client: false,
                pretty: true
            },
            files: [ {
              cwd: "app/views",
              src: "**/*.jade",
              dest: "build/templates",
              expand: true,
              ext: ".html"
            } ]
        }
    }

So if your source is structured as so:

app
└── views
    └── main.jade
    └── user
        └── signup.jade
        └── preferences.jade

grunt jade will create the following structure

build
└── templates
    └── main.html
    └── user
        └── signup.html
        └── preferences.html

EDIT: The grunt-contrib-jadeis deprecated. You should rather use grunt-contrib-pug. It is exactly the same, but they had to rename jade to pug!

这篇关于Grunt编译Jade文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆