问题 Bootstrap 3.0 with Brunch的字体文件


我想包括Bootstrap 3.0的字形文件(aka,glyphicons-halflings-regular.woff,.ttf,.svg)。 Bower成功将它们拉下来,我已将它们添加到我的应用程序中bower.json文件的“覆盖”部分:

"bootstrap": {
  "main": [
    "dist/js/bootstrap.js",
    "dist/css/bootstrap.css",
    "dist/fonts/glyphicons-halflings-regular.woff",
    "dist/fonts/glyphicons-halflings-regular.ttf",
    "dist/fonts/glyphicons-halflings-regular.svg"   
  ],

但据我所知,这没有任何效果。我可能需要强制更新bower因为我没有对Bootstrap进行版本更新,因为我添加了对字体文件的引用。除此之外,我不知道如何让Brunch将这些文件放入 ./public/fonts 目录。


10655
2017-09-20 15:28


起源



答案:


手动将它们复制到 app/assets 或者。 Brunch目前没有从bower获取文件,我们正在寻找一种好方法。


8
2017-09-21 10:15



好吧,对于Bower来说,这将是一个很好的补充,但我现在可以手动使用它。谢谢,期待看到您提出的解决方案。顺便说一句,是否有推特手柄,RSS提要或其他任何我可以调整以获取早午餐的更新? - ken
@brunch twitter - Paul Miller
同样的问题,很高兴!也许另外“类型”和“javascripts / stylesheets / templates”一起? - Dominic Tancredi


答案:


手动将它们复制到 app/assets 或者。 Brunch目前没有从bower获取文件,我们正在寻找一种好方法。


8
2017-09-21 10:15



好吧,对于Bower来说,这将是一个很好的补充,但我现在可以手动使用它。谢谢,期待看到您提出的解决方案。顺便说一句,是否有推特手柄,RSS提要或其他任何我可以调整以获取早午餐的更新? - ken
@brunch twitter - Paul Miller
同样的问题,很高兴!也许另外“类型”和“javascripts / stylesheets / templates”一起? - Dominic Tancredi


这是经过测试并与早午餐1.8.3一起使用。

我发现用bootstrap和其他带有字体资源的库来解决这个问题的最好方法如下:

1)首先,使用覆盖引导程序(或其他库)更新您的bower.json文件。您可以在下面看到main已更新为bootstrap,现在brunch可以访问fonts,js和css文件。

{
  "name": "Example",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "bootstrap": "3.3.x",
  },
  "overrides": {
    "bootstrap": {
      "main": [
        "dist/css/bootstrap.css",
        "dist/js/bootstrap.js",
        "dist/fonts/glyphicons-halflings-regular.eot",
        "dist/fonts/glyphicons-halflings-regular.svg",
        "dist/fonts/glyphicons-halflings-regular.ttf",
        "dist/fonts/glyphicons-halflings-regular.woff",
        "dist/fonts/glyphicons-halflings-regular.woff2"
      ],
      "dependencies": {
        "jquery": ">= 1.9.1"
      }
    }
  }
}

2)更新brunch-config.js中资产的约定。您可以使用函数来创建自定义约定。下面的函数有2个正则表达式,对应于资产的默认测试和我为字体文件添加的新正则。您可以根据需要添加更多正则表达式语句。

exports.config = {
  conventions: {
    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;
      // /^app\/.*\.html/.test(path) ||
      // RegExp for anything we need
      return /assets[\\/]/.test(path) 
            || /.*(?:\.eot|\.svg|\.ttf|\.woff2|\.woff)/.test(path); 
    }
  }
};
  1. 使用after-brunch插件为字体设置正确的文件结构。

    exports.config = {
      stylesheets: {
        joinTo: {
          'styles/app.css': /^styles/,
          'styles/vendor.css': /^(vendor|bower_components)/,
        }
      },
      conventions: {
        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;
          // /^app\/.*\.html/.test(path) ||
          // RegExp for anything we need
          return /assets[\\/]/.test(path) 
                || /.*(?:\.eot|\.svg|\.ttf|\.woff|\.woff2)/.test(path); 
        }
      },
      plugins: {
        afterBrunch: [
         [
           'mkdir public/fonts -p',
           'mv public/bootstrap/dist/fonts/* public/fonts',
           'rm -r public/bootstrap',
         ].join(' && ')
      ]
     }
    };
    

请注意,在上面的代码中,css和字体放在特定的目录中,因为css引用了特定位置的字体所以需要它才能正常工作:

  src: url('../fonts/glyphicons-halflings-regular.eot');

1
2018-06-26 20:06



加一解决。如果我可以给加号二,那就是使用多个正则表达式。或者他们称之为regexi。 - Dominic Tancredi
忘了最后一件事,检查上面更新的第三步。 - user13653