'Why both `stylesheet_link_tag` and `stylesheet_pack_tag` are needed to install bootstrap?
I have gone through this article to install bootstrap in ruby-on-rails app.
And I noticed that there are stylesheet_link_tag
and stylesheet_pack_tag
for css. I wonder why both is needed, isn't one is enough in app/views/layouts/application.html.erb
?
<head>
<title>BootstrapDemo</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
</head>
Solution 1:[1]
stylesheet_pack_tag 'application'
is a webpacker
helper method, it loads styles that are imported in app/javascript/packs/application.js
. If you set up bootstrap in app/javascript/
then pack tags are required.
stylesheet_link_tag 'application'
is a sprockets
helper method, it loads styles from app/assets/stylsheets/application.css
. If you don't use that file for anything then stylesheet_link_tag can be removed.
app/
assets/ # used by sprockets aka rails asset pipeline
stylesheets/
application.css # stylesheet_link_tag 'application'
javascripts/
application.js # javascript_include_tag 'application'
javascript/ # used by rails webpacker
packs/
application.js # javascript_pack_tag 'application'
# stylesheet_pack_tag 'application' # => includes 'styles.css'
stylesheets/
styles.css # must be imported in packs/application.js
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |