Skip to content
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

Replace browserify-rails with rails-webpacker #1835

Merged
merged 1 commit into from
Feb 13, 2018

Conversation

jmhooper
Copy link
Member

@jmhooper jmhooper commented Dec 2, 2017

Why: rails-webpacker compiles the assets much faster than
browserify-rails. With browserify-rails, our assets take so long to
compile that the initial requests to the idp time out locally. I have
not observed that with webpacker.

Additionally, rails-webpacker is recommended by the maintainer of
browserify-rails for projects that have already made the step towards
using commonjs modules.

One tradeoff of this is that rails-webpacker expects yarn, so we'll need
to move from npm to yarn for this to work.

Another tradeoff is that teaspoon does not appear to play nicely with
rails-webpacker, so I removed it and replaced it with a bare-metal
mocha.

Hi! Before submitting your PR for review, and/or before merging it, please
go through the following checklist:

  • For DB changes, check for missing indexes, check to see if the changes
    affect other apps (such as the dashboard), make sure the DB columns in the
    various environments are properly populated, coordinate with devops, plan
    migrations in separate steps.

  • For route changes, make sure GET requests don't change state or result in
    destructive behavior. GET requests should only result in information being
    read, not written.

  • For encryption changes, make sure it is compatible with data that was
    encrypted with the old code.

  • Do not disable Rubocop or Reek offenses unless you are absolutely sure
    they are false positives. If you're not sure how to fix the offense, please
    ask a teammate.

  • When reading data, write tests for nil values, empty strings,
    and invalid formats.

  • When calling redirect_to in a controller, use _url, not _path.

  • When adding user data to the session, use the user_session helper
    instead of the session helper so the data does not persist beyond the user's
    session.

on roles(:app, :web), in: :sequence do
within release_path do
execute :npm, 'install'
execute :yarn, 'install'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging, we'll want to work with devops to make sure yarn is available.

@tbaxter-18f
Copy link
Contributor

My general preference would be to run webpack directly as needed, but I think these are really solid changes.

@jmhooper
Copy link
Member Author

jmhooper commented Dec 4, 2017

@tbaxter-18f: The downside of running webpack directly is we loose a few of the benefits of the assets pipeline, like the use of tag helpers to load thumbprinted assets. I've managed to work around that by bundling assets into the asset load path, but that gets messy and with larger bundles can mean we see more performance issues.

@jmhooper
Copy link
Member Author

jmhooper commented Dec 4, 2017

Also, note that the code climate issues are related to files I moved, not files I've changed. I can fix the issues in them if we think it is a priority, but I'd prefer to keep the diff here small.

@jmhooper
Copy link
Member Author

jmhooper commented Dec 4, 2017

I'm going to move this down to WIP. Looks like we'll need to move up to node v6 or v8 to use @rails/webpacker and yarn.

@jmhooper jmhooper changed the title Replace browserify-rails with rails-webpacker [WIP] Replace browserify-rails with rails-webpacker Dec 4, 2017
@jmhooper jmhooper force-pushed the jmhooper-use-webpacker branch from 19a9d49 to 34bd40b Compare December 4, 2017 19:18
@jmhooper jmhooper changed the title [WIP] Replace browserify-rails with rails-webpacker Replace browserify-rails with rails-webpacker Dec 4, 2017
@monfresh
Copy link
Contributor

monfresh commented Feb 9, 2018

@jmhooper Wanna rebase with master?

cp config/application.yml.example config/application.yml
cp certs/saml.crt.example certs/saml.crt
cp keys/saml.key.enc.example keys/saml.key.enc
bin/generate-example-keys
bundle exec rake db:setup --trace
bundle exec rake assets:precompile
bundle exec rake db:setup --trace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we already have this on line 65.

== javascript_include_tag 'misc/i18n-strings'
- unless controller_name == 'home'
== javascript_include_tag 'application'
== javascript_include_tag 'i18n-strings'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be javascript_pack_tag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the i18n-strings use ERB so I've left it in the app directory for now. One thing to think about after we handle this may be to move that into a template like we do with the session timeout javascript.

- unless controller_name == 'home'
== javascript_include_tag 'application'
== javascript_include_tag 'i18n-strings'
== javascript_pack_tag 'application'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the controller conditional anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a "home" controller exists anymore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh. you're right!

@jmhooper
Copy link
Member Author

jmhooper commented Feb 9, 2018

@monfresh: Addressed the things you mentioned and brought this up to date with master. Should be good to go now.

Also note the synk issue is a false positive IIRC. It relates to using the dep in a Node.js app which we are not doing.

Copy link
Contributor

@monfresh monfresh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@monfresh monfresh force-pushed the jmhooper-use-webpacker branch 4 times, most recently from 05034c1 to a96a460 Compare February 13, 2018 14:06
**Why**: rails-webpacker compiles the assets much faster than
browserify-rails. With browserify-rails, our assets take so long to
compile that the initial requests to the idp time out locally. I have
not observed that with webpacker.

Additionally, rails-webpacker is recommended by the maintainer of
browserify-rails for projects that have already made the step towards
using commonjs modules.

One tradeoff of this is that rails-webpacker expects yarn, so we'll need
to move from npm to yarn for this to work.

Another tradeoff is that teaspoon does not appear to play nicely with
rails-webpacker, so I removed it and replaced it with a bare-metal
mocha.
@monfresh monfresh force-pushed the jmhooper-use-webpacker branch from a96a460 to 0996a19 Compare February 13, 2018 16:15
@monfresh monfresh merged commit e4af8bf into master Feb 13, 2018
@monfresh monfresh deleted the jmhooper-use-webpacker branch February 13, 2018 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants