Revisit css:build using the yarn:install task #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This restores use of the
yarn:install
task from #42, but adds a conditional for Rails 6.x to parallel existing behavior on those Rails versions, which addresses #43.This does mean that yarn install will be skipped on Rails 6.x if
bin/yarn
doesn't exist, but this was already true forassets:precompile
with webpacker anyway.Rails 6.x apps migrating from webpacker will usually have
bin/yarn
already. Apps migrating from just sprockets without webpacker may not, but this should be infrequent. Rails 6.x apps that want yarn install to run automatically can:a) create
bin/yarn
,b) add their own task dependency on
yarn:install
, orc) include
yarn:install
when building css or precompiling:rails yarn:install build:css
orrails yarn:install assets:precompile
.Rails 7 apps will continue to call
yarn:install
automatically, which uses yarn via the PATH and not bin/yarnBackground:
Rails 6.x's
yarn:install
requiresbin/yarn
to exist. If not present, it silently skips adding a dependency onyarn:install
fromassets:precompile
.Reasoning:
I think there's still value in using the
yarn:install
task as it performs more than a simpleyarn install
. In addition to ensuring yarn install only runs once (via rake's dependency mechanism),yarn:install
also setsNODE_ENV
and adds some flags to the execution. If an app needs to customizeyarn:install
, it also provides a single point to do so.Another alternative is to remove yarn install entirely and let apps call
yarn:install
on their own (or evenyarn install --custom-flags
), just like they callbundle install
. Build scripts that still want to use the task could simply add it before precompile, ie:rails yarn:install assets:precompile
.