8

Using a version of what grunt-contrib-watch recommends for compiling only changed files in here: https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed

var changedFiles = Object.create(null);

var onChange = grunt.util._.debounce(function() {
grunt.config('jshint.all.src', Object.keys(changedFiles));
   changedFiles = Object.create(null);
}, 200);

grunt.event.on('watch', function(action, filepath) {
   changedFiles[filepath] = action;
   onChange();
});

This works fine (again with a variation I wrote for it here: https://gist.github.com/pgilad/6897875)

The problem is when using include inside Jade templates, meaning you are including other Jade templates in order to build the complete html file.

Using the singular solution for compile doesn't work because if a .jade file you are working on is embeded using include current_working_jade.jade - the including file won't get recompiled.

Are there any workarounds for this besides compiling all of your jade files from scratch? This causes a problem when you have around ~60 large jade files to compile every time.

The only possible solution I can think of is either mapping jade templates dependencies either externally or with directories, but I don't know any tools/plugins which do that...

4

2 に答える 2

4

一種のヒスイを生成する足場の作業をすでに開始した後、sourcemapこの問題を解決する素晴らしいプロジェクトを見つけました。

翡翠の継承

使用方法は次のとおりです。

  1. 以下を使用してパッケージをインストールします。npm install jade-inheritance --save-dev
  2. ジェイドから依存ファイルのリストを取得する場所:

    var JadeInheritance = require('jade-inheritance');

    var inheritance = new JadeInheritance(file, basedirname, {basedir:basedirname});

  3. 次に、ファイルを取得する場合:

    depenedentFiles = inheritance.files;

  4. grunt.watchこのプロジェクトは、変更されたファイルとその依存ファイルのみをコンパイルするために、概念を適用する方法も示していますjade。まさに私が必要としていたものです。

grunt watch での jade-inheritance の使用

于 2013-12-14T15:09:34.823 に答える