轨道 3 和开发/生产模式下的资产管道

发布于 2025-01-07 09:40:05 字数 797 浏览 4 评论 0原文

在生产服务器上预编译资产非常慢。因此,我决定在开发机器上重新编译它们,并通过 jammit 将资源上传到 Amazon S3。一切都完成了,但我有一些负面问题:

  1. 我必须将 public/assets 目录包含到 git 控制中。因为如果生产服务器上的 public/assets 目录为空,则会失败
  2. 如果我在开发计算机上预编译资产 application.js 包含在压缩的 HTML 中,这样我就复制了js 代码。更改 js 不会产生任何效果,因为预编译的 application.js 会中断此代码。

这样,我的开发过程包括以下步骤:

  1. 如果我要更改 js 或 css,则删除预编译资产
  2. 进行一些更改
  3. 预编译资产
  4. 通过 jammit-s3 将资产上传到 S3
  5. 提交并推送我的更改(包括资产)到 git 服务器
  6. 由 capistrano 部署

我的问题是:

  1. 如果我将压缩的 application.js 放在 public/assets 目录中,是否可以配置开发环境不包含压缩的 application.js
  2. 是否可以将生产环境配置为使用空的 public/assets 目录?资产仅位于 S3 服务器上。

Precompiling assets on the production server is very slow. So I have decided to recompile them on the development machine and upload assets to the Amazon S3 by jammit. Everything's done but I have some negative problems:

  1. I have to include public/assets directory to git control. Because if public/assets directory is empty on the production server fails
  2. If I precompile assets on the development machine application.js includes in the HTML as compressed and that way I have duplicated js code. Changing js doesn't make any effect because precompiled application.js interrupts this code.

That way my development process includes following steps:

  1. Remove precompiled assets if I'm going to change js or css
  2. Do some changes
  3. Precompile assets
  4. Upload assets to S3 by jammit-s3
  5. Do commit and push my changes including assets to the git server
  6. Deploy by capistrano

My questions are:

  1. Is it possible to configure development environment don't include compressed application.js if I have it in public/assets directory?
  2. Is it possible to configure production environment to work with empty public/assets directory? Assets will only be on the S3 server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无尽的现实 2025-01-14 09:40:05

对于问题一,我不知道除了运行之外的永久解决方案:

bundle exec rake assets:clean

在切换回开发模式之前。我很想知道您是否可以忽略正在开发的资产而不关闭整个资产管道。

在 Production.rb 中,有一个选项可以解决您的第二个问题:

# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "http://assets.example.com"

然后它应该忽略您的资产目录,因为它依赖于远程主机。
希望有帮助。

For question one I don't know a permanent solution other than running:

bundle exec rake assets:clean

before you switch back to development mode. I'd be interested to see if you can just ignore the assets in development without turning the entire assets pipeline off.

In production.rb there is an option for your second question:

# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "http://assets.example.com"

It should then ignore your assets directory since it relies on the remote host.
Hope that helps.

他不在意 2025-01-14 09:40:05

我通过在 gitignore 中包含资产目录并仅排除一个文件 - public/assets/manifest.yml 解决了这个问题,并且生产服务器现在可以正常工作,即 config.action_controller.asset_host = "http: //assets.example.com" 有效。它只需要 manifest.yml 文件

I resolved this problem by including assets dir in gitignore and exclude only one file - public/assets/manifest.yml and production server works correctly now, i.e. config.action_controller.asset_host = "http://assets.example.com" works. It requires only manifest.yml file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文