【问题标题】:Brunch config file conventions.assets: How to copy from non-default locations?早午餐配置文件conventions.assets:如何从非默认位置复制?
【发布时间】:2018-09-25 09:40:12
【问题描述】:

根据早午餐文档,配置文件中的属性“conventions.assets”应该是一个正则表达式,但我试图包含以下内容:

conventions: {
    assets: /^app\/.*\.html/
}

为了将所有的 html 添加到公用文件夹中。 (我知道我可以创建一个 assets 文件夹并在其中包含所有内容,但根据我们同意的结构,目前还不可能)。

我认为这个属性需要一个目录,在这种情况下我可以修复这个值以达到我的目标吗?也许有一个函数?

【问题讨论】:

    标签: brunch


    【解决方案1】:

    最后我可以覆盖属性“资产”接受的方法。

    assets: function(path) {
        /**
         * Loops every path and returns path|true|false according what we need
         * @param   path    file or directory's path
         * @returns path    if it is a directory
         *          true    if it fit with the regular expression
         *          false   otherwise
         *
         */
        if( /\/$/.test(path) ) return path;
        return /^app\/.*\.html/.test(path); // RegExp for anything we need
    }
    

    【讨论】:

      【解决方案2】:

      只是想如果有人很难弄清楚如何继续,我会评论我的功能:

      assets: function(path) {
       /**
        * Loops every path and returns path|true|false according what we need
        * @param   path    file or directory's path
        * @returns path    if it is a directory
        *          true    if it fit with the regular expression
        *          false   otherwise
        *
        */
        if( /\/$/.test(path) ) return path;
        return /^(app|assets)\/.*\.(html|png|jpg|jpeg|eot|svg|ttf|woff)/.test(path);
      }
      

      这会将app-和assets-文件夹中的文件移动到public-文件夹中,扩展名为html, png, jpg, jpeg, eot, svg, ttf, woff

      我决定将我们的assets-文件夹移动到根结构,所以我们的结构现在看起来像这样:

      frontend
        - app
        -- common/
        -- styles/
        -- etc etc
        - assets
        -- index.html
        -- css/
        -- images/
        -- etc etc
      

      【讨论】:

      • 您是否还必须将frontend/assets 添加到paths.watched?对配置进行任何其他更改以使您的资产结构正常工作吗?谢谢!
      • @cxw 是的!但是,由于某种原因,我们今天没有使用 assets-override。我们的paths.watched 包括"app""assets"
      猜你喜欢
      • 2018-08-27
      • 2013-03-17
      • 2016-05-24
      • 2016-10-07
      • 2017-01-28
      • 1970-01-01
      • 2016-04-23
      • 1970-01-01
      • 2015-09-03
      相关资源
      最近更新 更多