Rails, NPM, Webpack integration through Assets pipeline

Dmitry Shvetsov
1 min readDec 19, 2016

--

Recently it became known that rails 5.1.0 will support NPM packages through yarn and webpack through webpacker. It’s just a feast! After this news I decided to share about how we have integrated NPM, webpack into rails in our company and happy to use this achievement.

Update: webpacker gem is a better solution and we migrate to it, so give it a try.

You have to know that webpacker requires Yarn package manager. If you prefer to use NPM over Yarn read this article.

Before you get a big piece of code I would like to point out that NPM, webpack, gulp, grunt, your option are connected into rails not for the first time. There are a number of solutions, such as the complete replacement of the rails assets pipeline and sprockets or independent neighborhood the latter with JavaScript automation tools. A year ago, I have not found a solution that would have used all of the advantages of both worlds. Moreover I have heard the view that it will end badly if we combine these tools with each other.

I have an opinion on this subject. You do not need to reinvent the wheel complicating everything in times. It not worth doing surgery with rails, this will hit you back later and may be really hard. You should stand on the shoulders of giants.

Now the solution.

If you have any ideas or opinion, do not hesitate to share them. I’m sure it will be interesting to discuss.

--

--

Dmitry Shvetsov
Dmitry Shvetsov

No responses yet