4

私は次のGruntfileようなものを持っています(例のために簡略化されています):

module.exports = (grunt) ->
  grunt.initConfig

    config:
      dev:
        options:
          variables:
            debug: true
      dist:
        options:
          variables:
            debug: false

    jade:
      templates:
        options:
          client: true
          compileDebug: '<%= grunt.config.get("debug") %>'
        files:
          'public/templates.js': ['src/jade/templates/**/*.jade']

  grunt.loadNpmTasks 'grunt-config'
  grunt.loadNpmTasks 'grunt-contrib-jade'

問題はgrunt-config(またはおそらくテンプレートの解析による) がすべてのオプションを文字列に変換することですが、Jade コンパイラはすべてのブール フラグ オプションをブール ( if (compileDebug !== false)) としてチェックします。そのため、 を実行grunt config:dist jadeしても、デバッグ ロジックが含まれたテンプレートが生成されます。

Jade の設定を 2 つの異なるターゲットに複製することでこれを回避できることはわかっていますが、Gruntfile を可能な限り DRY に保ちたいと考えています。これを行う方法はありますか?

4

1 に答える 1

0

これを行う方法が見つからなかったため、次の機能を備えた grunt プラグインを作成しました。

https://npmjs.org/package/grunt-reconfigure

于 2013-07-11T22:16:19.907 に答える