Webpacker: How to build and load for production?

Created on 25 Sep 2017  路  6Comments  路  Source: rails/webpacker

I had a minification bug in production, and I wanted to test it locally. In other webpack repositories, I would just build as production and serve the distribution. How can I do this with Rails and webpacker?

Most helpful comment

For webpacker to compile the packs in production environment just set NODE_ENV=production before your compiler either ./bin/webpack or ./bin/webpacker --watch

# Procfile to use with foreman
web: bundle exec rails s
webpacker: NODE_ENV=production ./bin/webpack --watch --colors --progress

All 6 comments

Not sure it will correctly serve the files, have you tried NODE_ENV=production RAILS_ENV=development rails server?

RAILS_ENV=production rails assets:precompile
or
RAILS_ENV=production rails server
should work.

For webpacker to compile the packs in production environment just set NODE_ENV=production before your compiler either ./bin/webpack or ./bin/webpacker --watch

# Procfile to use with foreman
web: bundle exec rails s
webpacker: NODE_ENV=production ./bin/webpack --watch --colors --progress

@kozhin That hits all the production services with Rails, so a little bit different from what I want. I just want the JS to be compiled as if production. Thanks, however.
@gauravtiwari Thanks, this looks like what I want.

Hello guys, is that normal that when I run RAILS_ENV=production bundle exec rake assets:precompile, I'm stuck with the command failing while it looks into .babelrc, which then requires a bunch of things that are located in devdependencies ? I have to move the whole babel related stuff in dependencies, which just sucks. And to remove the jest setup which is also involved then

It just looks like the comand does not care about the environment and builds for dev.

What am I supposed to do at this point ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itay-grudev picture itay-grudev  路  3Comments

eriknygren picture eriknygren  路  3Comments

iChip picture iChip  路  3Comments

inopinatus picture inopinatus  路  3Comments

towry picture towry  路  3Comments