22

すべての Jade ファイルを個々の HTML ファイルにコンパイルするように Gruntfile を構成しようとしています。たとえば、次のソース フォルダーがあるとします。

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

次に、出力することを期待grunt jadeします:

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

これが私のGruntfilegrunt-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");
};

ただし、 jade コマンドを実行すると、次のエラーが発生します。

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

私は何を間違っていますか?

4

3 に答える 3

50

上記の回答を完了するには

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

したがって、ソースが次のように構成されている場合:

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

grunt jade次の構造を作成します

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

編集:grunt-contrib-jadeは非推奨です。むしろ使用する必要がありますgrunt-contrib-pug。まったく同じですが、jade を pug に改名する必要がありました。

于 2013-11-09T21:04:44.807 に答える