diff --git a/CHANGELOG.md b/CHANGELOG.md index ec9bf4995..ee043afdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ ## [Unreleased] Changes since last non-beta release. -- Added `append_stylesheet_pack_tag` helper, which is required for filesystem-based automated Component Registry API on React-on-Rails. +### Added +- `append_stylesheet_pack_tag` helper. It helps in configuring stylesheet pack names from the view for a route or partials. It is also required for filesystem-based automated Component Registry API on React on Rails gem. [PR 144](https://github.com/shakacode/shakapacker/pull/144) by [pulkitkkr](https://github.com/pulkitkkr). _Please add entries here for your pull requests that are not yet released._ diff --git a/README.md b/README.md index 74f541e13..ddea85031 100644 --- a/README.md +++ b/README.md @@ -282,10 +282,8 @@ However, you typically can't do that in the main layout, as the view and partial Thus, you can distribute the logic of what packs are needed for any route. All the magic of splitting up the code and CSS was automatic! -**Important:** `append_javascript_pack_tag` can be used anywhere in your application as long as it is executed BEFORE the `javascript_pack_tag`. If you attempt to call `append_javascript_pack_tag` helper after `javascript_pack_tag`, an error will be raised. You should have only a single `javascript_pack_tag` invocation in your page load. +**Important:** Both `append_(javascript/stylesheet)_pack_tag` helpers can be used anywhere in your application as long as they are executed BEFORE `(javascript/stylesheet)_pack_tag` respectively. If you attempt to call one of the `append_(javascript/stylesheet)_pack_tag` helpers after the respective `(javascript/stylesheet)_pack_tag`, an error will be raised. -**Important** Similar to `append_javascript_pack_tag`, the `append_stylesheet_pack_tag` should be used anywhere in your application as long as it is executed BEFORE the `stylesheet_pack_tag`. However, if you attempt to call `append_stylesheet_pack_tag` helper after `stylesheet_pack_tag`, an error will be **NOT** be raised. - The typical issue is that your layout might reference some partials that need to configure packs. A good way to solve this problem is to use `content_for` to ensure that the code to render your partial comes before the call to `javascript_pack_tag`. ```erb diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index a33f2b426..2c7afa93c 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -98,7 +98,7 @@ def favicon_pack_tag(name, **options) def javascript_pack_tag(*names, defer: true, **options) if @javascript_pack_tag_loaded raise "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " \ - "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide" + "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide" end append_javascript_pack_tag(*names, defer: defer) @@ -169,7 +169,7 @@ def stylesheet_pack_tag(*names, **options) def append_stylesheet_pack_tag(*names) if @stylesheet_pack_tag_loaded raise "You can only call append_stylesheet_pack_tag before stylesheet_pack_tag helper. " \ - "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide" + "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide" end @stylesheet_pack_tag_queue ||= [] @@ -179,7 +179,7 @@ def append_stylesheet_pack_tag(*names) def append_javascript_pack_tag(*names, defer: true) if @javascript_pack_tag_loaded raise "You can only call append_javascript_pack_tag before javascript_pack_tag helper. " \ - "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide" + "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide" end hash_key = defer ? :deferred : :non_deferred diff --git a/test/helper_test.rb b/test/helper_test.rb index ec3530787..272b4d6c0 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -133,7 +133,7 @@ def test_append_javascript_pack_tag_raises assert_equal \ "You can only call append_javascript_pack_tag before javascript_pack_tag helper. " + - "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide", + "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide", error.message end @@ -161,7 +161,7 @@ def test_javascript_pack_tag_multiple_invocations assert_equal \ "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " + - "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide", + "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide", error.message end