首页 > 解决方案 > Rails 中如何使用“manifest.json”

问题描述

manifest.json文件:预编译资产和指纹资产之间的映射。

我明白它是什么,但它是如何使用的?

在 Webpacker 设置中,有一条评论指出 # Cache manifest.json for performance

好的,但是什么工作是manifest.json执行缓存它使它更快?

标签: ruby-on-railswebpacker

解决方案


Webpacker::Manifest为我们提供了这些信息。

# Singleton registry for accessing the packs path using a generated manifest.
# This allows javascript_pack_tag, stylesheet_pack_tag, asset_pack_path to take a reference to,
# say, "calendar.js" or "calendar.css" and turn it into "/packs/calendar-1016838bab065ae1e314.js" or
# "/packs/calendar-1016838bab065ae1e314.css".
#
# When the configuration is set to on-demand compilation, with the `compile: true` option in
# the webpacker.yml file, any lookups will be preceded by a compilation if one is needed.

当 Rails 想要calendar.jsmanifest.json 时说要在/packs/calendar-1016838bab065ae1e314.js. 稍后在代码中有一个示例。

Webpacker.manifest.lookup('calendar.js') # => "/packs/calendar-1016838bab065ae1e122.js"

推荐阅读