0
0
Ruby on Railsframework~20 mins

Webpacker and JavaScript bundling in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Webpacker Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you run bin/webpack in a Rails app using Webpacker?
You run bin/webpack in your Rails project that uses Webpacker. What is the main result of this command?
AIt compiles and bundles JavaScript files into a single pack file in <code>public/packs</code>.
BIt starts a Rails server to serve JavaScript files dynamically.
CIt deletes all JavaScript files from the <code>app/javascript</code> folder.
DIt installs new JavaScript packages from <code>package.json</code>.
Attempts:
2 left
💡 Hint
Think about what bundling means for JavaScript files in Rails.
📝 Syntax
intermediate
2:00remaining
Which Webpacker config file defines the entry points for JavaScript bundling?
In a Rails app using Webpacker, which file specifies the JavaScript entry points that Webpack uses to start bundling?
Aconfig/webpack/environment.js
Bapp/javascript/packs/application.js
Cpackage.json
Dconfig/webpacker.yml
Attempts:
2 left
💡 Hint
Look for the JavaScript file that acts as the entry point for bundling.
🔧 Debug
advanced
3:00remaining
Why does this Webpacker build fail with a syntax error?
Given this JavaScript pack file content, why does Webpacker fail to build it?
import React from 'react'
import ReactDOM from 'react-dom'

const App = () => {
  return 
Hello World
} ReactDOM.render(, document.getElementById('root'))
AThe import statements must use double quotes instead of single quotes.
BReactDOM.render is deprecated and causes a build error.
CThe <code>document.getElementById</code> call is invalid in Webpacker.
DThe JSX syntax requires a Babel loader configured, which is missing.
Attempts:
2 left
💡 Hint
Think about what Webpack needs to understand JSX syntax.
state_output
advanced
2:30remaining
What is the output of this Webpacker manifest JSON after bundling?
After running Webpacker, the manifest.json file contains mappings of source files to compiled assets. Given this snippet:
{
  "application.js": "/packs/js/application-123abc.js",
  "styles.css": "/packs/css/styles-456def.css"
}
What does this mean for the Rails app?
AThe manifest file causes Webpacker to delete the original source files.
BRails will ignore these files and serve the originals from <code>app/javascript</code>.
CRails will serve the compiled JavaScript and CSS files with hashed names for caching.
DThe manifest file is only used for development and ignored in production.
Attempts:
2 left
💡 Hint
Think about why hashed filenames are used in web apps.
🧠 Conceptual
expert
3:00remaining
Which statement best describes the role of Webpacker in modern Rails apps?
Choose the most accurate description of what Webpacker does in a Rails application.
AWebpacker manages JavaScript and CSS bundling, allowing Rails to use modern JavaScript tools and frameworks seamlessly.
BWebpacker only handles CSS preprocessing and does not affect JavaScript files.
CWebpacker replaces the Rails asset pipeline entirely and removes the need for Sprockets.
DWebpacker is a Rails server extension that dynamically compiles assets on every request.
Attempts:
2 left
💡 Hint
Consider what Webpacker adds to Rails compared to the traditional asset pipeline.