Writing Code Using Webpacker
In development, we mostly worry about three things: writing our code, getting our code on to the page, and being able to recompile the code quickly and easily.
Somewhat uncharacteristically for Rails, Webpacker does not suggest any structure for your code beyond having the entry point be in app/packs/entrypoints. The important feature is that you can import files relative to either app/packs (for your own code) or node_modules (for third-party code).
That said, some suggestions:
-
Keep as little code as possible in your actual entry point; it should mostly just import things.
-
Where possible, having multiple modular small pack files is probably better than having a single one. (There’s a webpack optimization that makes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access