Complete the code to import a JavaScript module using Webpacker in Rails.
import [1] from 'components/button';
You import the module by its exported name, which is usually capitalized like Button.
Complete the code to add a JavaScript pack tag in a Rails view.
<%= javascript_pack_tag '[1]' %>
The default pack file is named application, so you include it with javascript_pack_tag 'application'.
Fix the error in the Webpacker config to enable source maps.
[1].devtool = 'source-map'; module.exports = [1];
The Webpacker config uses environment to customize settings like source maps.
Fill both blanks to create a Webpack alias for easier imports.
environment.config.[1].alias = { '@components': path.[2](__dirname, '../../app/javascript/components') };
You set aliases under resolve.alias and use path.join to build paths.
Fill all three blanks to configure Babel loader in Webpacker.
environment.loaders.append('babel', { test: /\.js$/, exclude: /node_modules/, use: { loader: '[1]', options: { presets: [ '[2]' ], plugins: [ '[3]' ] } } });
The Babel loader is called babel-loader. The preset @babel/preset-env compiles modern JS, and the plugin @babel/plugin-transform-runtime optimizes helper code.