如何在预编译资产时临时更改输出路径,Sprockets / Rails 资产管道,3.1.0
我正在尝试更新此代码以与已发布的 Rails 3.1.0 配合使用:
# temporarily set the static assets location from public/assets to our spec directory
::Rails.application.assets.static_root = Rails.root.join("spec/javascripts/generated/assets")
::Rake.application['assets:clean'].invoke
::Rake.application['assets:precompile'].invoke
既然 Sprockets::Environment#static_root 已被删除,那么临时更改 sprockets 输出目录的最佳方法是什么?
编辑:我还希望能够清理自定义输出目录中的资产:)
I'm trying to update this code to work with the released Rails 3.1.0:
# temporarily set the static assets location from public/assets to our spec directory
::Rails.application.assets.static_root = Rails.root.join("spec/javascripts/generated/assets")
::Rake.application['assets:clean'].invoke
::Rake.application['assets:precompile'].invoke
Now that Sprockets::Environment#static_root has been removed, what's the best way temporarily change the sprockets output directory?
Edit: Also I'd like to be able to clean the assets in my custom output directory :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 config.assets.prefix,但这仍然会将资产放在公共目录中(请参阅此处 用于 rake 任务,它连接
public_path
和前缀)。在您的情况下,这应该可行:
由于链轮轨带的奇怪加载顺序,我必须指定清单路径。如果不这样做,它就会卡在不存在的
public/assets
上,并破坏 rake 任务。 YMMV。旁注:我首先在开发环境中尝试过此操作,但 config.assets.prefix 拒绝更改。我怀疑将 config.assets.enabled 设置为 true 可以解决此问题,但我还没有时间测试它。
作为奖励,
assets:clean
与此解决方案完美配合(您可以亲自查看它在 rake 任务中)You can use
config.assets.prefix
, but this will still put the assets in the public directory (see here for the rake task, which joins thepublic_path
and the prefix).In your case, this should work:
I had to specify the manifest path because of the weird load order of the sprockets railtie. Without doing it, it gets stuck at
public/assets
, which doesn't exist and blows up the rake task. YMMV.Side note: I tried this in the development environment at first, but the
config.assets.prefix
refused to change. I suspect puttingconfig.assets.enabled
totrue
would have fixed this, but I haven't got around to testing it yet.As a bonus, the
assets:clean
works perfectly with this solution (you can see it for yourself in the rake task)