Webpack integration landed in Rails 5.1 to a bit of excitement and confusion. On one hand, folks who had been using Javascript frameworks like Angular and React now have a clearer way to tie in their client-side application into the asset pipeline. Yet, why would we want to do this? What’s the purpose of adding Webpack to Rails, and what’s the advantage of utilizing it? How does this affect javascript frameworks that aren’t Webpack friendly? In this talk, we’ll explore these ideas as well as the future of client side integrations into Rails.
16. @hiimtaylorjones
What is Webpack?
• Used as a means for bundling together modules of
javascript-based code.
• Takes multiple bundles and optimizes them based on your
preferences
• Takes dependency-driven code and converts it into static
assets that are optimized for direct consumption by web
clients.
47. @hiimtaylorjones
Extendable Webpack
•Webpack only understands Javascript. It can only
“bundle” JS assets.
•We create Loaders to help teach Webpack how to
compile more complex languages and
configurations
•Plugins are created to help compress, minify, and
manipulate existing bundles.
50. @hiimtaylorjones
Why Integrate it
Directly Into
Rails? Why not just use it outside of Rails?
Why not just keep using those
various language gems you’ve
installed over the years?
52. @hiimtaylorjones
A Brief History of The Asset Pipeline
• Introduced around Rails 3.1(Railsconf
2011)
• Was a solution to the problem of
disorganized and scattered javascript
and css files in Rails.
• A variety of features have been built
around it and its become the foundation
for how Rails handles Javascript-like
pieces of code.
53. @hiimtaylorjones
Why The Asset Pipeline?
•Organizing Javascript
•Supporting new languages via
gem interfaces. (Remember the
example before?)
•Using your selected wrappers and
languages to tie directly into Rails
generator functions.
🤔 🤔
🤔
55. @hiimtaylorjones
How Processing Works with Gems
This allows for us to write more “abstract” code in Sass that
directly compiles to CSS and is automatically inserted into
the Asset Pipeline for optimization.
Sass CSS Optimized CSS
64. @hiimtaylorjones
Webpack and the Asset
Pipeline have similar
approaches towards
optimizing assets.
This is why they’re candidates to work well
together. Adding Webpacker allows Rails to
support more modern iterations of frontend
languages better and faster.
68. @hiimtaylorjones
Rails thrives on consistency.
Having a community supported
option for Webpack helps smooth
out any differences in
implementations we might find.
77. @hiimtaylorjones
Turbolinks has been a project
that works really well for
some folks but isn’t really
cared for by others.
This is a absolutely ok.
78. @hiimtaylorjones
You not only have to work to
introduce a new idea, but
you also have to sell it to
others.
Both of these are really hard.
80. @hiimtaylorjones
Webpack integration (via
Webpacker) is special because its
taking something that’s already
been successful in a community
setting and giving it a means to
bind with Rails.
A lot less selling is required.