<commit_before>---
title: 25 reasons to switch to Webpacker
author: <NAME>
published: true
summary: Leaving behind the Rails asset pipeline
description: There are plenty of great reasons to switch to Webpacker, including improvements in supported syntax, development tooling, performance optimizations, and more. For Rails developers considering the upgrade from the Rails asset pipeline, start here.
pull_image: 'blog/stock/alice-donovan-packing-unsplash.jpg'
pull_image_caption: Photo by <NAME> on Unsplash
series:
category: Code
tags:
  - Rails
  - Webpack
---

_Should you switch to Webpacker?_

In this post, I'll offer you some reasons why.

_But Webpack sounds complicated... is the steep learning curve worth the tradeoff?_

To make that call, you should first consider why you might NOT want to switch and stick with the Rails asset pipeline instead:

1. **You don't have the right application**

    If your application doesn't use much JavaScript, it's probably not worth the switch. Do you spend less than 5-10% of your development time working on JavaScript? Your app might not warrant a heavier tool like Webpack.

1. **You don't have the time**

    I'll be the first to admit that adopting Webpack for the first time requires patience. Things work differently than with Sprockets. You may need to invest time learning a new paradigm. Webpack and NPM dependencies are upgraded at a rapid pace, so you will may also need to work to keep up with upgrades. You might also need to understand how JavaScript modules work—good news, those skills are transferrable.

1. **You don't have the right mindset**

    Yes, Webpack is complex. Plenty of developers love to complain about this fact. If you think you're one of those developers, you probably won't enjoy the process of adopting Webpack. Given the time and motivation, a lot of the frustration can be eased through education. Make sure you've got a positive attitude going in.

---

However, given a little time, the need, and the right mindset, you'll be successful upgrading to Webpacker. Here's a list of ways you'll benefit.

### 1. Webpacker is the future of Rails

  Webpacker is now the default JavaScript compiler for new Rails apps. Rails 6 apps will still include both Sprockets for managing CSS and images, but JavaScript dependencies are meant to be bundled by Webpacker. The Rails defaults fall in line with how Basecamp builds web applications and it may benefit your team to "go with the herd" to stay closer to Rails edge and attract candidates who are looking to work with more advanced tools.

### 2. Sprockets is dead; Long live Sprockets

Sprockets development may have slowed in recent years, but it's not going away anytime soon. Sprockets version 4 was recently released, thanks to hard work led by <NAME>. The default Rails setup encourages developers to use both Webpacker (for JavaScript compilation) and Sprockets (for CSS and images) side-by-side.

The ability to use both compilers in the same application is a real advantage for teams making the switch; this opens the door to an iterative migration which may be desirable for larger applications to de-risk the transition from Sprockets to Webpackexr.

### 3. It will change the way you write JavaScript for the better

Prior to Rails support for Webpack through Webpacker, most of the Rails apps I've worked on or seen either directly on GitHub or implicitly through tutorials or presentations, have fallen into one of the following categories:<commit_msg>Edits<commit_after>---
title: 25 reasons to switch to Webpacker
author: <NAME>
published: true
summary: Leaving behind the Rails asset pipeline
description: There are plenty of great reasons to switch to Webpacker, including improvements in supported syntax, development tooling, performance optimizations, and more. For Rails developers considering the upgrade from the Rails asset pipeline, start here.
pull_image: 'blog/stock/alice-donovan-packing-unsplash.jpg'
pull_image_caption: Photo by <NAME> on Unsplash
series:
category: Code
tags:
  - Rails
  - Webpack
---

​I've been getting this question lately in some form or another:

_Is Webpack and Webpacker worth the hassle?_

It's a good question but my short answer is _yes_.

Given the sharp rise of mindshare in the JavaScript community in recent years, there has been a great deal of innovation in tooling, development experience, and optimization for frontend development.

Rails was once at the forefront—the Rails asset pipeline was a huge leap forward when it was released—but it hasn't kept up in this department. Outsourcing JavaScript and CSS dependency management and asset bundling is smart economics at this point.

In this post, I will elaborate on why I think think it's a good idea to make the switch. But this will assume some prerequisites; in other words, we'll first consider why you might NOT want to switch and instead stick with the Rails asset pipeline.

1. **You don't have the right application**

    If your application doesn't use much JavaScript, it's probably not worth the switch. Do you spend less than 5-10% of your development time working on JavaScript? Your app might not warrant a heavier tool like Webpack.

1. **You don't have the time**

    I'll be the first to admit that adopting Webpack for the first time requires patience. Things work differently than with Sprockets. You may need to invest time learning a new paradigm. Webpack and NPM dependencies are upgraded at a rapid pace, so you will may also need to work to keep up with upgrades. You might also need to understand how JavaScript modules work—good news, those skills are transferrable.

1. **You don't have the right mindset**

    Yes, Webpack is complex. Plenty of developers love to complain about this fact. If you think you're one of those developers, you probably won't enjoy the process of adopting Webpack. Given the time and motivation, a lot of the frustration can be eased through education. Make sure you've got a positive attitude going in.

---

All that said, given a little time, the need, and the right mindset, you'll be successful upgrading to Webpacker. Here's a list of ways you'll benefit.

### 1. Webpacker is the future of Rails

  Webpacker is now the default JavaScript compiler for new Rails apps. Rails 6 apps will still include both Sprockets for managing CSS and images, but JavaScript dependencies are meant to be bundled by Webpacker. The Rails defaults fall in line with how Basecamp builds web applications and it may benefit your team to "go with the herd" to stay closer to Rails edge and attract candidates who are looking to work with more advanced tools.

### 2. Sprockets is dead; Long live Sprockets

Sprockets development may have slowed in recent years, but it's not going away anytime soon. Sprockets version 4 was recently released, thanks to hard work led by <NAME>. The default Rails setup encourages developers to use both Webpacker (for JavaScript compilation) and Sprockets (for CSS and images) side-by-side.

The ability to use both compilers in the same application is a real advantage for teams making the switch; this opens the door to an iterative migration which may be desirable for larger applications to de-risk the transition from Sprockets to Webpackexr.

### 3. It will change the way you write JavaScript for the better

Prior to Rails support for Webpack through Webpacker, most of the Rails apps I've worked on or seen either directly on GitHub or implicitly through tutorials or presentations, have fallen into one of the following categories:
{'fraction_non_alphanumeric': 0.04066543438077634, 'fraction_numerical': 0.003432796408766834, 'mean_word_length': 4.4496402877697845, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1692095', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1767, 'n_words': 1190}