Skip to content

Update the Asset Pipeline guide - #47012

Closed
matuszewskijan wants to merge 1 commit into
rails:mainfrom
matuszewskijan:asset-pipeline-guide
Closed

matuszewskijan wants to merge 1 commit into
rails:mainfrom
matuszewskijan:asset-pipeline-guide

Conversation

@matuszewskijan

@matuszewskijan matuszewskijan commented Jan 14, 2023 •

Copy link
Copy Markdown
Contributor

Motivation / Background

This Pull Request has been created because the actual asset pipeline guide were outdated in many ways:

  • It was likely written for Rails 4, a lot of stuff not relevant anymore
  • Not mentioning the importmaps-rails as the default solution for JavaScript
  • The sprockets guide was written before Sprockets 4.0 so it never mentioned the manifest.js file and some parts were not relevant anymore
  • The jsbundling-rails, cssbundling-rails, dartsass-rails and tailwindcss-rails gems weren't mentioned at all

Detail

This Pull Request changes the Asset Pipeline guide to reflect the Rails 7 asset pipeline configuration.

Additional information

I've started my work by taking the #45400 draft PR. But in fact it wasn't too helpful and in the end, I've rewritten almost everything by myself.

For the Importmap section, I've mostly copied the Readme from the importmap-rails gem.

Sprockets section changes:

  • tried to avoid showing that it could also handle the JavaScript to not confuse the readers, I am not sure if the new version is clear enough?
  • There was a lot of info about older Sprockets versions and I did my best to find and update all of the outdated parts, is the refreshed version still correct and understandable?
  • I've also removed all of the SCSS mentions there as we should point anyone interested in Sass to use dartsass-rails instead of the unmaintained sassc-rails gem
  • Also removed all of the CoffeeScript mentions

About the last Alternative Libraries section: I've tried to only give a clue for the readers to show that there are other resources that might be useful for them. Isn't it too short?

First time contributing so I'd highly appreciate any feedback!

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot Bot added the docs label Jan 14, 2023
@matuszewskijan matuszewskijan changed the title Update the Asset pipeline guide Update the Asset Pipeline guide Jan 14, 2023
Comment thread guides/source/asset_pipeline.md Resolved
@ghiculescu

Copy link
Copy Markdown
Member

This is awesome. When you are happy with it, could you squash down to a single commit please.

Comment thread guides/source/asset_pipeline.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for a first time user this is probably a bit technical, it's talking about concepts they may have never come across or don't care about.

For someone coming from a package.json world it's great, but I don't know if it needs to be the first thing you see here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this part to show import maps more like an "alias" for the library source address, as it's the simplest definition of an import map I could think of. What do you think about the newer version?

Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Webpacker has been the default JavaScript pre-processor and bundler for Rails 5 and 6. `Webpacker` successor is now [`shakapacker`](https://github.com/shakacode/shakapacker) and it's advised to use it.
Webpacker was the default JavaScript pre-processor and bundler for Rails 5 and 6. It has now been retired. A successor called [`shakapacker`](https://github.com/shakacode/shakapacker) exists, but is not maintained by the Rails team or project.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first line of README in Shakapacker repo goes like this:

Official, actively maintained successor to rails/webpacker.

If it's not maintained by Rails team then maybe they shouldn't use the official word, but anyway I like the rewording there and going to commit it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what official means in that context. It was added in shakacode/shakapacker#14

I suggested that wording because it's not part of the rails/ github org so isn't owned by the same core team.

cc @justin808 you may have some thoughts on this (or on this PR in general).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's official in the sense that @dhh recommends it as the successor, and he came up with the name "shakapacker."

See https://github.com/rails/webpacker.

Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
@ghiculescu

Copy link
Copy Markdown
Member

I think the only other notable thing missing from this guide is https://github.com/rails/propshaft

@matuszewskijan

Copy link
Copy Markdown
Contributor Author

I think the only other notable thing missing from this guide is https://github.com/rails/propshaft

I asked a few questions on Rails Discord before posting this PR, and one of them was about Propshaft. DHH answered that it's a Rails 8 thing so I believe we could skip it for now. https://discord.com/channels/849034466856665118/987190327616090182/1061971064449675264

This is awesome. When you are happy with it, could you squash down to a single commit please.

I will squash it all, let's wait a few more days as I posted it on weekend so maybe there will be more feedback and more commits to come.

@zzak

zzak commented Jan 16, 2023

Copy link
Copy Markdown
Member

This is huge. Thanks for working on it!

giphy

@rafaelfranca rafaelfranca added this to the 7.1.0 milestone Jan 16, 2023
@matuszewskijan

Copy link
Copy Markdown
Contributor Author

This is awesome. When you are happy with it, could you squash down to a single commit please.

Done.

@hachi8833

hachi8833 commented Feb 11, 2023 •

Copy link
Copy Markdown
Contributor

Awesome!
We'd be glad if you merge this PR to https://github.com/rails/rails/tree/7-0-stable branch as well because current asset_pipeline.md in 7-0-stable is pretty confusing while translating. @rafaelfranca

@zzak

zzak commented Feb 13, 2023

Copy link
Copy Markdown
Member

An error occurred when trying to build this locally, can you take a look? I will try to debug it during my day tomorrow if not:

Generating asset_pipeline.md as asset_pipeline.html
/Users/zzak/code/rails/guides/rails_guides/markdown.rb:47:in `dom_id': undefined method `[]' for nil:NilClass (NoMethodError)

          dom_id = "#{nodes[-2][:id]}-#{dom_id}"
                               ^^^^^
        from /Users/zzak/code/rails/guides/rails_guides/markdown.rb:115:in `block (2 levels) in generate_structure'
        from /Users/zzak/.gem/ruby/3.3.0/gems/nokogiri-1.13.10/lib/nokogiri/xml/node_set.rb:234:in `block in each'
        from /Users/zzak/.gem/ruby/3.3.0/gems/nokogiri-1.13.10/lib/nokogiri/xml/node_set.rb:233:in `upto'
        from /Users/zzak/.gem/ruby/3.3.0/gems/nokogiri-1.13.10/lib/nokogiri/xml/node_set.rb:233:in `each'
        from /Users/zzak/code/rails/guides/rails_guides/markdown.rb:100:in `block in generate_structure'
        from <internal:kernel>:90:in `tap'
        from /Users/zzak/code/rails/guides/rails_guides/markdown.rb:97:in `generate_structure'
        from /Users/zzak/code/rails/guides/rails_guides/markdown.rb:29:in `render'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:160:in `generate_guide'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:85:in `block in generate_guides'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:83:in `each'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:83:in `generate_guides'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:40:in `generate'
        from rails_guides.rb:30:in `<main>'

You should be able to reproduce it by running bundle exec rake guides:generate from the guides directory.

@matuszewskijan

Copy link
Copy Markdown
Contributor Author

An error occurred when trying to build this locally, can you take a look? I will try to debug it during my day tomorrow if not:

Generating asset_pipeline.md as asset_pipeline.html
/Users/zzak/code/rails/guides/rails_guides/markdown.rb:47:in `dom_id': undefined method `[]' for nil:NilClass (NoMethodError)

          dom_id = "#{nodes[-2][:id]}-#{dom_id}"
                               ^^^^^
        from /Users/zzak/code/rails/guides/rails_guides/markdown.rb:115:in `block (2 levels) in generate_structure'
        from /Users/zzak/.gem/ruby/3.3.0/gems/nokogiri-1.13.10/lib/nokogiri/xml/node_set.rb:234:in `block in each'
        from /Users/zzak/.gem/ruby/3.3.0/gems/nokogiri-1.13.10/lib/nokogiri/xml/node_set.rb:233:in `upto'
        from /Users/zzak/.gem/ruby/3.3.0/gems/nokogiri-1.13.10/lib/nokogiri/xml/node_set.rb:233:in `each'
        from /Users/zzak/code/rails/guides/rails_guides/markdown.rb:100:in `block in generate_structure'
        from <internal:kernel>:90:in `tap'
        from /Users/zzak/code/rails/guides/rails_guides/markdown.rb:97:in `generate_structure'
        from /Users/zzak/code/rails/guides/rails_guides/markdown.rb:29:in `render'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:160:in `generate_guide'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:85:in `block in generate_guides'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:83:in `each'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:83:in `generate_guides'
        from /Users/zzak/code/rails/guides/rails_guides/generator.rb:40:in `generate'
        from rails_guides.rb:30:in `<main>'

You should be able to reproduce it by running bundle exec rake guides:generate from the guides directory.

Ah sorry there was one conflict I resolved in the wrong way, it should be fixed now.

Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
Comment thread guides/source/asset_pipeline.md Resolved
@matuszewskijan
matuszewskijan force-pushed the asset-pipeline-guide branch 2 times, most recently from 45118f3 to be69bb1 Compare February 25, 2023 13:20
@matuszewskijan

Copy link
Copy Markdown
Contributor Author

@hachi8833 thank you for the review, I've fixed all of your points, and I've also found a few small typos and fixed them too. I've squashed all of the commits and rebased them with main.

Awesome! We'd be glad if you merge this PR to https://github.com/rails/rails/tree/7-0-stable branch as well because current asset_pipeline.md in 7-0-stable is pretty confusing while translating. @rafaelfranca

According to this one, this branch is having conflicts with 7-0-stable as I've rebased with the main. Shall I rebase it to 7-0? I've created another branch in my local repo diverged from 7-0-stable with the guide update commit(this branch is here: https://github.com/matuszewskijan/rails/tree/asset-pipeline-guide-7-0). I could open an PR with the secondary branch but I don't want to ping everyone so could you advise me how to do it best?

@hachi8833

Copy link
Copy Markdown
Contributor

Thank you very much for the fixing! I appreciate for your works❤️

@matuszewskijan I think rebasing the branch to 7-0-stable branch is OK and seems safer. I see that merging it would cause conflicts.

Comment thread guides/source/asset_pipeline.md Resolved
@matuszewskijan
matuszewskijan changed the base branch from main to 7-0-stable February 27, 2023 18:19
@matuszewskijan
matuszewskijan force-pushed the asset-pipeline-guide branch 2 times, most recently from 4997ab6 to acde79e Compare February 27, 2023 18:21
@matuszewskijan

Copy link
Copy Markdown
Contributor Author

Thank you very much for the fixing! I appreciate for your works❤️

@matuszewskijan I think rebasing the branch to 7-0-stable branch is OK and seems safer. I see that merging it would cause conflicts.

Done, I've rebased this branch with 7-0-stable and changed base branch of this pull request to 7-0-stable. Hope it's all good, appreciate your comments!

@zzak

zzak commented Mar 3, 2023

Copy link
Copy Markdown
Member

@matuszewskijan @hachi8833 I think what we want to do is get this merged to main first and then backport the merge commit. If there are conflicts between main and stable we can fix them then. Does that make sense?

@hachi8833

Copy link
Copy Markdown
Contributor

@zzak yes, I should've explained more...

Add back Sprockets guide(with remarks) to Asset Pipeline guide

Describe Import Maps in asset pipeline guide

Small rewording to first chapters of Asset Pipeline guide

Remove Sass and CoffeScript from Codin Links to Assets section

Remove Preprocessing section from Asset Pipeline guide

Mention dartsass-rails and rewrite beginning Asset Pipeline guide

Add more details on `rails-importmaps` in Asset Pipeline guide

Add alternative libraries section

Align Asset Pipeline guide Sprockets section for Sprockets V4

Improve the introduction to Asset Pipeline guide

Fix formatting in Importmap-rails section of Asset Pipeline guide

Reword, fix typos and add more context to the Asset Pipeline guide

Style, formatting and cleanup changes for asset pipeline guide

Minor style/typo fixes to Asset Pipeline guide

Remove sections dobuled by mistake from asset pipeline guide

Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Co-authored-by: Breno Gazzola <breno.gazzola@gmail.com>
Co-authored-by: Shozo Hatta <hachi8833@gmail.com>
@matuszewskijan
matuszewskijan changed the base branch from 7-0-stable to main March 9, 2023 09:56
@matuszewskijan

Copy link
Copy Markdown
Contributor Author

@matuszewskijan @hachi8833 I think what we want to do is get this merged to main first and then backport the merge commit. If there are conflicts between main and stable we can fix them then. Does that make sense?

@zzak yes, I should've explained more...

No worries, it was actually my misunderstanding, I've changed the base branch to be again main.

@hachi8833

Copy link
Copy Markdown
Contributor

Thank you for the changing branch!

zzak added a commit to zzak/rails that referenced this pull request Mar 22, 2023
@zzak

zzak commented Mar 22, 2023

Copy link
Copy Markdown
Member

Was able to get this to build locally with matuszewskijan#1, for anyone else interested in reviewing, I think this screenshot of the intro and chapter guide is a nice start:

Screenshot 2023-03-22 at 12 27 38

It does feel like Sprockets could be it's own guide at this point though 🤔

@matuszewskijan

Copy link
Copy Markdown
Contributor Author

Was able to get this to build locally with matuszewskijan#1, for anyone else interested in reviewing, I think this screenshot of the intro and chapter guide is a nice start:

Screenshot 2023-03-22 at 12 27 38

It does feel like Sprockets could be it's own guide at this point though 🤔

Hey Zak, thanks for checking the branch, this section you deleted was supposed to be deleted, but I was rebasing the whole stuff many times and it seems that it sneaked back in the process. Thanks for fixing it!

Definitely, Sprockets could have its own guide. But maybe some of the basics are still useful there, still, a lot of stuff in the default setup is dependent on Sprockets.

@zzak

zzak commented Mar 24, 2023

Copy link
Copy Markdown
Member

Definitely, Sprockets could have its own guide. But maybe some of the basics are still useful there, still, a lot of stuff in the default setup is dependent on Sprockets.

Yeah, this is the Sprockets guide, you're 💯 right. I'm not sure what was going through my head at the time 😂.

Are you able to update your branch so that the guide builds here? I'd love to get this reviewed and merged. 🙏

@hachi8833

Copy link
Copy Markdown
Contributor

@rafaelfranca it seems the PR is ready to merge. I hope you'd check this 🙏, apart from creating a new Sprockets guide.
cc: @zzak

@zzak

zzak commented Apr 7, 2023

Copy link
Copy Markdown
Member

This needs a rebase, I'm happy to pitch in and help if that would move things along faster. Just want to make sure!

@zzak zzak mentioned this pull request Apr 9, 2023
4 tasks done
@zzak

zzak commented Apr 9, 2023

Copy link
Copy Markdown
Member

Since I don't have edit access to @matuszewskijan's fork, I opened #47899 and merged. Thanks everyone for pitching in here!

@zzak zzak closed this Apr 9, 2023
@matuszewskijan

Copy link
Copy Markdown
Contributor Author

Since I don't have edit access to @matuszewskijan's fork, I opened #47899 and merged. Thanks everyone for pitching in here!

Thank you @zzak, I am so happy to see my first contribution merged! Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants