【问题标题】:How to copy fonts folder from node_module using Brunch如何使用早午餐从 node_module 复制字体文件夹
【发布时间】:2017-01-28 23:55:35
【问题描述】:

我正在关注这篇博文,但字体没有被复制。

http://cloudless.studio/articles/4-installing-font-awesome-from-npm-in-phoenix

说明

问题的本质是什么? 不包括字体文件夹

预期行为

我希望包含字体文件夹

环境

  1. 早午餐:2.8.2
  2. 节点:v6.3.1
  3. NPM:3.10.3
  4. 操作系统:OS X 10.11.6

package.json内容

{
  "repository": {},
  "license": "MIT",
  "scripts": {
    "deploy": "brunch build --production",
    "watch": "brunch watch --stdin"
  },
  "dependencies": {
    "font-awesome": "^4.6.3",
    "google-maps": "^3.2.1",
    "phoenix": "file:deps/phoenix",
    "phoenix_html": "file:deps/phoenix_html",
    "sass-brunch": "^2.6.3"
  },
  "devDependencies": {
    "babel-brunch": "~6.0.0",
    "brunch": "~2.8.0",
    "clean-css-brunch": "~2.0.0",
    "css-brunch": "~2.0.0",
    "javascript-brunch": "~2.0.0",
    "uglify-js-brunch": "~2.0.1"
  }
}

早午餐配置内容

exports.config = {
  // See http://brunch.io/#documentation for docs.
  files: {
    javascripts: {
      joinTo: "js/app.js"

      // To use a separate vendor.js bundle, specify two files path
      // http://brunch.io/docs/config#-files-
      // joinTo: {
      //  "js/app.js": /^(web\/static\/js)/,
      //  "js/vendor.js": /^(web\/static\/vendor)|(deps)/
      // }
      //
      // To change the order of concatenation of files, explicitly mention here
      // order: {
      //   before: [
      //     "web/static/vendor/js/jquery-2.1.1.js",
      //     "web/static/vendor/js/bootstrap.min.js"
      //   ]
      // }
    },
    stylesheets: {
      joinTo: "css/app.css",
      order: {
        after: ["web/static/css/app.css"] // concat app.css last
      }
    },
    templates: {
      joinTo: "js/app.js"
    }
  },

  conventions: {
    // This option sets where we should place non-css and non-js assets in.
    // By default, we set this to "/web/static/assets". Files in this directory
    // will be copied to `paths.public`, which is "priv/static" by default.
    assets: [
      /^(web\/static\/assets)/,
            /^(node_modules\/font-awesome)/
    ]
  },

  // Phoenix paths configuration
  paths: {
    // Dependencies and current project directories to watch
    watched: [
      "web/static",
      "test/static",
        'node_modules/font-awesome/fonts',
    ],

    // Where to compile files to
    public: "priv/static"
  },

  // Configure your plugins
  plugins: {
    babel: {
      // Do not use ES6 compiler in vendor code
      ignore: [/web\/static\/vendor/]
    }
  },

  modules: {
    autoRequire: {
      "js/app.js": ["web/static/js/app"]
    }
  },

  npm: {
    enabled: true
  }
};

【问题讨论】:

    标签: elixir phoenix-framework brunch


    【解决方案1】:

    我使用copycat-brunch 插件来做到这一点,这很简单。在我做的 brunch-config.js 文件中:

    plugins: {
        copycat: {
          fonts: [
            "node_modules/font-awesome/fonts",
            "node_modules/bootstrap/dist/fonts"
          ]
        }
    }
    

    字体已正确复制到 priv/static/fonts。它也适用于图像。

    【讨论】:

      【解决方案2】:

      Omin 的回答非常简洁,所以我会尝试提供更多详细信息。

      从最近版本的 brunch 开始,通过 node_modules 提供的非 JavaScript 或 CSS 资产将不包含在 Brunch 中。

      指南here 指出,包含非 JavaScript 或 CSS 资产的唯一方法是手动复制它们。它建议通过 npm 中的 postinstall 挂钩来执行此操作。

      那么这在您的 phoenix 应用程序中会是怎样的呢?很简单..

      在你的 package.json 中:

      "scripts": { "postinstall": "cp -R node_modules/font-awesome/fonts web/static/assets/fonts" }

      最终我不认为这个解决方案很好,但它确实完成了工作。在文章中,您列出了作者指向一组great alternatives 的链接,因为他们意识到他们的方法从早午餐 2.8.2 起不再适用。

      在使用 webpack 的替代方案中,似乎是最好的替代方案之一。 Phoenix 可以很好地与 webpack 配合使用,他们甚至提供了关于 how to do just that. 的简短指南

      【讨论】:

      • 是的...当我发现时我真的很失望(有点生气)。我最终也使用了postinstallelixirforum.com/t/…。无论如何,感谢您抽出宝贵时间彻底回答问题。
      【解决方案3】:

      不要将 node_modules 归类为“资产”,即使它们与 正则表达式

      https://github.com/brunch/brunch/blob/41f0c1f298bf94024621457c66caee74ea6d4ddc/CHANGELOG.md#brunch-26-apr-2-2016

      【讨论】:

        猜你喜欢
        • 2016-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-03
        • 2015-11-14
        • 2012-10-18
        • 1970-01-01
        相关资源
        最近更新 更多