CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 8
Migrate from webpack-rails to Webpacker #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This gets rid of a weird bug where the Webpack-generated manifest.json file was coming up empty. Took me a bit of staring back and forth betweeen this repo and a pristine 5.2 Webpacker one to see that we didn't need a "webpack" entry in our package.json βΒ it's a transitive dependency of "@rails/webpacker" so let's just rely on that one instead.
This is the only static css file in the app, and was inherited from ReactAutosuggest. Webpacker doesn't seem be loading this (even though we appear to have CSS loader and this file should be reachable from the entry point for this app?) So I'm just doing this dumb thing right now, and hope to undo it one way or another
And also 5x faster, by skipping node_modules
Prior to this commit we were inadvertently using Webpacker's default behavior of compiling assets only on demand. This commit restores the status quo β packs are compiled as their source files are changed.
host: localhost | ||
port: 3035 | ||
public: localhost:3035 | ||
hmr: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is enabling HMR in webpacker as simple as setting this to true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering the same π βΒ once this migration is complete I should try that out. Thanks for the reminder!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah super curious, like if turning this on injects the other pesky required HMR bits into the JS automatically...
I believe the requestAnimationFrame polyfill is not required to run Jest specs ever since jestjs/jest#4568 (which landed in Jest v22) And the webpack dev server config was specific to the old webpack-rails gem βΒ doesn't work with Webpacker, but also does not seem to be needed for CI to work.
Let's be honest with ourselves π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonallured this mini-epic is ready for ya now.
@@ -1,6 +1,5 @@ | |||
Rails.application.configure do | |||
config.active_record.dump_schema_after_migration = false | |||
config.webpack.dev_server.enabled = !ENV['CI'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle seems fine without this, but lmk if you think this might still be needed @jonallured ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looks great!!
"stats-webpack-plugin": "^0.2.1", | ||
"style-loader": "^0.20", | ||
"styled-components": "^2.0", | ||
"webpack": "^1.9.11", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was left over from the webpack-rails config and was pointing to a very old version π±
app/javascript/test/setup.js
Outdated
@@ -1,4 +1,4 @@ | |||
import 'raf/polyfill' | |||
// import 'raf/polyfill' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later in this PR this gets deleted altogether, it's no longer needed as of Jest v22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome work @anandaroop, thank you so much!! I've tried to do this twice and gotten stalled both times, so I know how much work it can be! Very thorough PR from what I can tell. I cloned it locally and everything is working as I expect so with Circle being green, I'm good with merging this and then we can kick the tires on staging. Maybe production deploy tomorrow assuming staging looks good.
- Gemfile | ||
- vendor/**/* | ||
- node_modules/**/* | ||
- bin/webpack* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
@@ -1,6 +1,5 @@ | |||
Rails.application.configure do | |||
config.active_record.dump_schema_after_migration = false | |||
config.webpack.dev_server.enabled = !ENV['CI'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looks great!!
@@ -1,2 +1,3 @@ | |||
web: bundle exec rails server | |||
worker: bundle exec sidekiq | |||
webpack: ./bin/webpack-dev-server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I've never had luck with the Rails server doing what I wanted, so I tend to run a dev server anyway - good to formalize this!
@@ -1,11 +0,0 @@ | |||
# v1.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π― π₯ π
assumed that while developing, you'll have `foreman` running (see next section), | ||
which means you'll have a webpack dev server running. If you see an error like | ||
this: | ||
project work together, we've added acceptance tests that run in Chrome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for simplifying this and then taking the time to update the README - should help the next person getting up-to-speed!! π
π― |
Turns out this will need a small migration once deployed to production (I just ran the staging equivalent now): heroku buildpacks:remove https://github.com/febeling/webpack-rails-buildpack.git --app rosalind-production The |
Problem
webpack-rails was the gem we used to tie Rails and Webpack together back in early 2017. At that point it was our best option, but now it is deprecated in favor of Rails' core Webpacker gem.
Solution
Migrate over to Webpacker. Roughly:
A lot more detail in the commits, hope the narrative is not too hard to follow.