I upgraded a project I built for learning purposes from react_on_rails version 7 to version 8.0.0 and noticed that when deploying to Heroku, webpack no longer generates a minified production build of React (I can tell because I'm using the react extension for Chrome).
I upgraded using the generator from scratch and moving my code to the newly generated /client folder.
The source code of my project can be found here.
This is also happening with the www.reactrails.com app on version 8.
Is this a bug? or am I missing something in the client/webpack.config.js file?
@serodriguez68 Good catch.
In the case of the generator, we're generating the simplest possible config file, so it's not optimized for production. We should probably use the "-p" option for Webpack (see references below).
https://webpack.js.org/guides/production/#the-automatic-way
The Automatic Way
Running webpack -p (or equivalently webpack --optimize-minimize --define process.env.NODE_ENV="production"). This performs the following steps:
Minification using UglifyJsPlugin
Runs the LoaderOptionsPlugin (see its documentation)
Sets the NodeJS environment variable triggering certain packages to compile differently
Please report that to the https://github.com/shakacode/react-webpack-rails-tutorial.
@Judahmeek @udovenko @robwise Opinions?
yeah use -p for the production script
And I found the devBuild variable in webpack.config.js always be true because of PR #877. It should be able to generate minified js file correctly after fix that.
Ideally the generator should produce a client/package.json file that is ready to go for production builds. I'm not familiar with react_on_rails codebase so I'm not sure where to make the change to make this happen.
Does doing the following change on this file makes the trick?
Change this:
"build:production": "NODE_ENV=production webpack --config webpack.config.js",
For this:
"build:production": "NODE_ENV=production webpack -p --config webpack.config.js",
@serodriguez68 馃挴
Please submit a PR and I'll merge it!
Even better if there's a unit test!
Also, please see https://github.com/shakacode/react_on_rails/blob/master/CONTRIBUTING.md for some basic PR hygiene like updating the https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md
Ok I just submitted PR 895 that fixes that.
Fixed in #895.
Most helpful comment
And I found the
devBuildvariable in webpack.config.js always betruebecause of PR #877. It should be able to generate minified js file correctly after fix that.