1

我想在早午餐中使用小胡子模板。这是我的 config.coffee 文件:

{languages, plugins} = require 'brunch-extensions'

# Make config loadable via require() for brunch.
exports.config =
  # Available plugins:
  # * AssetsPlugin: copy `app/assets` contents to `build/`
  plugins: [plugins.AssetsPlugin]

  # Contains a list of output filenames that your application would generate.
  # Format:
  #
  # 'filename': 
  #   languages:
  #     'regExp, with which input files will be matched': language class
  #   order:
  #     before: [files, that would be loaded before anything else]
  #     after: [files, that would be loaded after anything else]
  #
  files:
    'scripts/app.js':
      languages:
        '\.js$': languages.JavaScriptLanguage
        '\.coffee$': languages.CoffeeScriptLanguage
        '\.eco$': languages.EcoLanguage
        '\.mustache$': languages.HoganLanguage
      order:
        before: [
          'vendor/scripts/console-helper.js'
          'vendor/scripts/jquery-1.7.js'
          'vendor/scripts/underscore-1.1.7.js'
          'vendor/scripts/backbone-0.5.3.js'
        ]

    'styles/app.css':
      languages:
        '\.css$': languages.CSSLanguage
        '\.styl$': languages.StylusLanguage
      order:
        before: ['vendor/styles/normalize.css']
        after: ['vendor/styles/helpers.css']

但是启动时出现以下错误brunch watch

[17:27:45]: [Brunch]: cannot parse config entry 
config.files['scripts/app.js'].languages['.mustache$']: TypeError: undefined is not a function.
4

1 回答 1

1

事实上,brunch-extensions 0.2.2 似乎没有胡子支持。您可以做的是直接从主分支安装早午餐扩展:

npm install https://github.com/brunch/brunch-extensions/tarball/master

HoganLanguage或者您可以从他们的 github添加自己的:

hogan = require 'hogan.js'
{BaseLanguage} = require './base'

# Requires Hogan 1.0.4
#
# Example:
# $(@el).html(template.render name: "mdp", city: "SF")
class exports.HoganLanguage extends BaseLanguage
  compile: (path, callback) ->
    @readFile path, (error, data) =>
      return callback error if error?
      try
        content = hogan.compile data, asString: yes
        callback null, "exports.render = function(data) {
          var t = new Hogan.Template();
          t.r = #{content};
          return t.render(data);
        }"
      catch error
        callback error

如果您只是安装hogan.js并更改为{BaseLanguage} = require 'brunch-extensions/lib/languages/base'上述内容,它应该可以正常工作。

于 2012-02-27T18:02:53.317 回答