【问题标题】:Rails app. Dependency installed with yarn. How to get to the files?轨道应用程序。使用纱线安装的依赖项。如何获取文件?
【发布时间】:2019-02-10 03:57:15
【问题描述】:

我有一个 Rails 应用程序。我用纱线安装了 fullPage.js 库。该库位于 node_modules 中。

如何在我的应用中加载文件?我正在尝试:

<link rel="stylesheet" type="text/css" href="fullpage.css" />

这不起作用。我明白了:

GET http://localhost:3000/fullpage.css 404(未找到)

我已经尝试在 application.scss 中导入这个文件,在 application.js 中。

我试着把整个路径:

<link rel="stylesheet" type="text/css" href="node_modules/fullpage.js/dist/fullpage.css" />

<link rel="stylesheet" type="text/css" href="/node_modules/fullpage.js/dist/fullpage.css" />

但我无法加载文件。有人能帮我理解一下,如何从 Rails 应用程序中的 node_modules 文件夹加载文件吗?

谢谢。

【问题讨论】:

    标签: ruby-on-rails yarnpkg


    【解决方案1】:

    在application.css中添加:

    *= require fullpage.js/dist/fullpage

    Rails 在加载资源时已经在 node_modules 目录中查找,所以你应该忽略它。

    【讨论】:

    • 感谢您的回答。我收到一个错误,rails 试图在以下路径中查找文件:app/assets/config、/app/assets/images、/app/assets/javascripts、/app/assets/stylesheets。我不明白他为什么不看 node_modules
    • 您的config/initializers/assets.rb 是否包含Rails.application.config.assets.paths &lt;&lt; Rails.root.join('node_modules')
    • yes: # 将 Yarn node_modules 文件夹添加到资产加载路径。 Rails.application.config.assets.paths
    猜你喜欢
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 2012-10-03
    • 2020-06-08
    • 1970-01-01
    • 2021-02-09
    • 2018-01-15
    • 1970-01-01
    相关资源
    最近更新 更多