DFE-Digital / rails-template

Rails 7 template with GOV.UK Frontend
27 stars 5 forks source link

No `build` or `build:css` script #24

Closed jsugarman closed 1 year ago

jsugarman commented 1 year ago

Great stuff 🎉

I followed the guide (not installing asdf however, which i had problems with) but when running bin/dev or rails assets:precompile or yarn build i received the error

$ yarn build                                                                                                                                                                                3s 
yarn run v1.22.19
error Command "build" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

similarly for yarn build:css

To correct it I manually added this to the generated package.json

{
  "name": "app",
  "private": "true",
  # ========== ADDED ========
  "scripts": {
    "build": "esbuild app/javascript/*.* --bundle --sourcemap --minify --outdir=app/assets/builds --public-path=assets --target=es6",
    "build:css": "sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --style=compressed --load-path=node_modules"
  },
  # =========================
  "dependencies": {
    "esbuild": "^0.17.10",
    "govuk-frontend": "4.4.1",
    "sass": "^1.58.3"
  },
  "devDependencies": {
    "@prettier/plugin-ruby": "^3.2.2",
    "prettier": "^2.8.4",
    ...

Not sure if it would be correct or how this would be done but it would great if this could be done as part of the template method that generates it

jsugarman commented 1 year ago

This issue seemed to resolve itself on a second app i spun up afterward - so 😕 now. But all good.

tvararu commented 1 year ago

That's weird...

Those lines should be included by jsbundling-rails and cssbundling-rails. It's these arguments to the rails new command that add them:

rails new \
  --database=postgresql \
  --skip-bundle \
  --skip-git \
  --skip-jbuilder \
  --skip-hotwire \
  --skip-action-mailbox \
  --skip-action-mailer \
  --skip-action-text \
> --asset-pipeline=propshaft \
> --javascript=esbuild \
> --css=sass \
  -m https://raw.githubusercontent.com/DFE-Digital/rails-template/main/template.rb \
  apply-for-a-juggling-licence

I have noticed some flaky/weird behaviour with rails new however sometimes, such as if the global Rails version which is installed on the system is a bit older.

jsugarman commented 1 year ago

Thanks @tvararu.

I wonder if, because I did not use asdf, whether my node version and/or yarn version at the time of the first apps rails new ... was different. I had updated to use node v18.1.0 (as per instructions) at some point before the trying it for the second app and that meant a smooth run.

jsugarman commented 1 year ago

closing as would say is not an issue if versions of installed tools are in place, as per instructions.