Module: Webpacker::Helper
- Defined in:
- lib/webpacker/helper.rb
Instance Method Summary collapse
-
#asset_pack_path(name, **options) ⇒ Object
Computes the relative path for a given Webpacker asset.
-
#asset_pack_url(name, **options) ⇒ Object
Computes the absolute path for a given Webpacker asset.
-
#javascript_pack_tag(*names, **options) ⇒ Object
Creates a script tag that references the named pack file, as compiled by webpack per the entries list in config/webpack/shared.js.
-
#stylesheet_pack_tag(*names, **options) ⇒ Object
Creates a link tag that references the named pack file, as compiled by webpack per the entries list in config/webpack/shared.js.
Instance Method Details
#asset_pack_path(name, **options) ⇒ Object
Computes the relative path for a given Webpacker asset. Return relative path using manifest.json and passes it to asset_path helper This will use asset_path internally, so most of their behaviors will be the same.
Example:
<%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
9 10 11 |
# File 'lib/webpacker/helper.rb', line 9 def asset_pack_path(name, **) asset_path(Webpacker.manifest.lookup!(name), **) end |
#asset_pack_url(name, **options) ⇒ Object
Computes the absolute path for a given Webpacker asset. Return absolute path using manifest.json and passes it to asset_url helper This will use asset_url internally, so most of their behaviors will be the same.
Example:
<%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
20 21 22 |
# File 'lib/webpacker/helper.rb', line 20 def asset_pack_url(name, **) asset_url(Webpacker.manifest.lookup!(name), **) end |
#javascript_pack_tag(*names, **options) ⇒ Object
Creates a script tag that references the named pack file, as compiled by webpack per the entries list in config/webpack/shared.js. By default, this list is auto-generated to match everything in app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
Example:
<%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
32 33 34 |
# File 'lib/webpacker/helper.rb', line 32 def javascript_pack_tag(*names, **) javascript_include_tag(*sources_from_pack_manifest(names, type: :javascript), **) end |
#stylesheet_pack_tag(*names, **options) ⇒ Object
Creates a link tag that references the named pack file, as compiled by webpack per the entries list in config/webpack/shared.js. By default, this list is auto-generated to match everything in app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
Note: If the development server is running and hot module replacement is active, this will return nothing. In that setup you need to configure your styles to be inlined in your JavaScript for hot reloading.
Examples:
# In development mode with hot module replacement:
<%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
nil
# In production mode:
<%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
<link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
52 53 54 55 56 |
# File 'lib/webpacker/helper.rb', line 52 def stylesheet_pack_tag(*names, **) unless Webpacker.dev_server.running? && Webpacker.dev_server.hot_module_replacing? stylesheet_link_tag(*sources_from_pack_manifest(names, type: :stylesheet), **) end end |