SprocketsからPropshaftへの移行に関する注意点
71 views
Post
Propshaft is an asset pipeline library for Rails. It's built for an era where bundling assets to save on HTTP connections is no longer urgent, where JavaScript and CSS are either compiled by dedicated Node.js bundlers or served directly to the browsers, and where increases in bandwidth have made the need for minification less pressing.
SprocketsからPropshaftへの移行手順は、 以下のPropshaftの公式手順で基本的には問題ないと思いますが、 この公式手順に記載されていないものを中心に、 移行における注意点をこのTopicで集約できればと思います。
https://github.com/rails/propshaft/blob/main/UPGRADING.md
Propshaftへの移行に際して、tailwindcss-railsまたはdartsass-railsを選ぶのもあり
Propshaftの公式移行手順では、CSS関連の処理が必要な場合の選択肢として cssbundling-rails のみ紹介されていますが、 tailwindcss-rails と dartsass-rails という選択肢もあります。cssbundling-railsのREADMEには、選び方のヒントが掲載されています。
Propshaftは.erbを処理しない
Sprocketsは拡張子が
.erbのファイル(例:foo.scss.erb)を処理しますが、Propshaftは処理しません。 そのため、Sprockets で.erbを処理している場合、Propshaftへ移行するには次のいずれかの対応が必要になります。.erbの利用をやめ、プレーンなCSS/SCSSなどに書き換える.erbの処理を、Propshaftに渡す前の前処理として別途組み込むPropshaftへ移行したらSprockets用の設定は削除可能
config/environments/production.rbにある以下の設定はSprocketsの設定なので、 Propshaftへ移行したら、削除可能です。参考情報
https://www.techtips.page/ja/comments/658