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?
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 ?
@benbonnet Please see this issue - https://github.com/rails/webpacker/issues/160 and https://github.com/rails/webpacker/issues/117
Most helpful comment
For webpacker to compile the packs in production environment just set
NODE_ENV=productionbefore your compiler either./bin/webpackor./bin/webpacker --watch