gpt4 book ai didi

ruby-on-rails - 什么是 public/packs 和 public/packs-test ?

转载 作者:行者123 更新时间:2023-12-01 23:16:28 26 4
gpt4 key购买 nike

在使用 webpack、webpacker gem 和 Rails 5.1 时,我注意到第一次运行 rspec 会生成 public/packs public/packs-test

  • 这些目录是干什么用的?
  • 两者有什么区别?
  • 是否应该通过版本控制进行跟踪?
  • 最佳答案

    Rails 中的 /public 文件夹是预编译 Assets 用于静态分发的地方(也就是在服务器启动时编译一次,因此它们不会在每次页面加载时编译)。这是 Rails asset pipeline 的一个特性,可以帮助加速 Assets 分配,因此 Rails 不必自己为它们服务。

    请注意 webpacker Assets 如何放置在 packs 目录中的 /app/assets 文件夹中。这些包将被预编译并放入 /public/packs 文件夹中,这些预编译包将在页面请求期间从中进入并提供服务。
    /public/packs-test 文件夹是测试环境包将被预编译到的位置。您可以在 config/webpacker.yml 文件中为每个环境配置预编译包的位置。

    至于是否通过版本控制来跟踪这些文件,这取决于您——这通常是一个关于部署到生产时需要做什么的逻辑问题。来自官方的 Ruby on Rails 指南:

    There are several reasons why you might want to precompile your assets locally. Among them are:

    • You may not have write access to your production file system.
    • You may be deploying to more than one server, and want to avoid duplication of work.
    • You may be doing frequent deploys that do not include asset changes.

    Local compilation allows you to commit the compiled files into source control, and deploy as normal.



    See the official Ruby on Rails Guide section 4.2 on Local Precompilation 出于更多原因(或为什么不)您想要预编译并将生成的文件提交到版本控制中。

    关于ruby-on-rails - 什么是 public/packs 和 public/packs-test ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45806389/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com