Installing Webpack in an existing Ruby On Rails application

After a few hours searching / reading blogs to make the Ruby On Rails project work integrated with the Webpack I decided to document the process.
First at all my project was generated at version 5.0.0, now is using ROR 5.1.4 (last stable) and Ruby 2.5.0.
What I’ll show in this post?

Webpack: Resolving older assets

After add
'app/assets' to
webpacker.yml each file on
app/assets you must import in the new
application.js at
app/javascripts/packs
The file may be like this

JavaScript

1

2

3

4

5

6

7

8

9

import'javascripts/admin/brands'

import'javascripts/admin/dashboard'

varname="Fabian";

varplace="Porto Alegre";

`Hello${name},readyfor${place}?`;

[1,2,3].map(n=>n**2);

Webpack: Compiling and Transpiling Assets

After each file modification you’ll need to run the
webpack in console to compile/transpile assets.
But to automate this process we’ll pass
watch parameter to webpack.
When passing this parameter, the webpack will be watching the files for changes