9

My Brunch template compiles all my code into app.js and all third party dependencies into vendor.js (a pretty standard approach). I'd like to do the same with CSS and it used to work but as I moved to using Bower something stopped working and I now get the following error:

Error: couldn't load config /path-to-root/config.coffee. SyntaxError: unexpected { at Object.exports.loadConfig (/usr/local/share/npm/lib/node_modules/brunch/lib/helpers.js:448:15)

from a configuration file (config.cofee) that looks like this:

files:
    javascripts:
      joinTo: 
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^(bower_components|vendor)/
        'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/

    stylesheets:
      joinTo:
        'stylesheets/app.css': /^app/
        'stylesheets/vendor.css': /^(bower_components|vendor)/

If I instead just strip out the two lines for stylesheets and put this single line in its place it works without error:

'stylesheets/vendor.css': /^(app|bower_components|vendor)/

I've been sort of living with this but this is causing more and more problems and I'd like to get it sorted. Any help would be greatly appreciated.

In case the question comes up ... the version of brunch I'm using is 1.7.6.

4

3 回答 3

4

我很困惑,但我认为 Paul 关于文件中可能有一个特殊字符的建议似乎很可能。我现在让它使用的配置似乎与之前不工作的配置相同。这是完整的配置文件:

sysPath = require 'path'

exports.config =
  # See http://brunch.io/#documentation for documentation.
  files:
    javascripts:
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^(bower_components|vendor)/
        'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/

    stylesheets:
      joinTo: 
        'stylesheets/app.css': /^app/
        'stylesheets/vendor.css': /^(bower_components|vendor)/

    templates:
      precompile: true
      root: 'templates'
      joinTo: 'javascripts/app.js' : /^app/

      modules:
        addSourceURLs: true

  # allow _ prefixed templates so partials work
  conventions:
    ignored: (path) ->
      startsWith = (string, substring) ->
        string.indexOf(substring, 0) is 0
      sep = sysPath.sep
      if path.indexOf("app#{sep}templates#{sep}") is 0
        false
      else
        startsWith sysPath.basename(path), '_'
于 2013-09-24T14:38:39.070 回答
2

这很奇怪,但我必须为同一案例执行以下操作(在末尾添加 /)

stylesheets: {
    joinTo: {
        'css/vendor.css': /^(vendor|bower_components)\//,
        'css/styles.css': /^app\/css\//
    }
}
于 2013-09-24T09:10:34.863 回答
1

我和肯有同样的问题。为我解决的只是从config.coffee文件中删除有问题的行,然后从头开始重新输入它们。这确保不存在隐藏字符并使脚本再次运行。

于 2014-07-19T11:10:15.893 回答