

So from the Rails point of view there is only another JavaScript file to include - and this JavaScript file is a bundle emitted by Webpack.


There is a npm script named build-production that creates the production-ready bundle (by production-ready I mean - deduped one).All JavaScript dependencies of the codebase are installed on the Node.js side as regular dependencies.Webpack, Babel and loaders are installed as devDependencies so they are not installed if Node.js environment is set to production.Webpack compiles the bundle into app/assets/javascripts directory and this bundle is required within application manifest ( application.js).Source files are stored under app/assets/source.The Node.js package.json resides under app/assets within the Rails application root.The assumption is that the stack is configured as follows: It doesn’t minify files - the assumption is that Rails’ asset pipeline can do this just fine during precompilation phase. In the described configuration Webpack only provides modularization and ES2015 compilation using babel-loader. In this article the goal is to make Webpack compile the bundle that can be used by Rails to serve this bundle. Of course to deploy Rails together with Heroku we need to have both tools configured and working. This is the thing that is expected from us by our clients from time to time. In this article I’d like to show you how you can deploy Rails + Webpack combo to Heroku. Apart from configuration and Rails integration problems there is also a problem of deployment and configuring the deploy machinery to wire everything together.
How to run webpack from heroku code#
In Arkency we use Webpack and Babel.js to manage and compile code written in modern dialects of JavaScript. That’s why modern JavaScript tooling is used more and more often to deliver those features. Using ECMAScript 2015 features, modern modularization tools and keeping track of dependencies are hard to achieve in typical Rails asset pipeline. In modern web applications backends and frontends are often equally sophisticated - and unfortunately solutions that Sprockets offers by default are suboptimal choice. It’s easy and it’s fast to host an app - and those two factors are very important in early stages of the project’s lifecycle. Heroku and Rails loves each other from long time - and this combo is still widely used both by beginners and experts to build and host their web applications. Creating custom Heroku buildpack for Webpack and Ruby on Rails integration
