【问题标题】:Heroku cannot serve files from bower_componentsHeroku 无法从 bower_components 提供文件
【发布时间】:2016-01-02 07:32:16
【问题描述】:

我无法让 Heroku 在 bower_components 文件夹中查找资源,但该站点在 localhost 上运行良好。

我创建了一个 express-node.js 站点。该网站的结构如下所示。

site
-> bower_components
--> jquery
---> dist
----> jquery.min.js
-> Other folders
-> app.js

我已经像这样公开了bower_components 文件夹。

app.use(express.static(path.join(__dirname, 'bower_components')));

为了检索 jquery 文件,我在 html 中指定了它

<script src="/jquery/dist/jquery.min.js"></script>

为什么这在 localhost 上有效,但在我将其部署到 Heroku 时无效?

【问题讨论】:

    标签: node.js heroku bower


    【解决方案1】:

    我通过将postinstall 放入package.json 来修复它

      "scripts": {
        "postinstall": "bower install"
      },
    

    【讨论】:

      【解决方案2】:

      确保 package.json 文件中有 bower 并包含安装后脚本

       "scripts": {
          "postinstall": "bower install"
        },
      

      如果你在 package.json 文件中没有 bower,同样会导致错误。

      【讨论】:

        猜你喜欢
        • 2019-01-19
        • 2017-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-05
        • 1970-01-01
        • 2011-07-22
        • 2013-05-23
        相关资源
        最近更新 更多