react_on_rails 8.0.0 not generating production builds by default

Created on 14 Jun 2017  路  7Comments  路  Source: shakacode/react_on_rails

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?

bug

Most helpful comment

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.

All 7 comments

@serodriguez68 Good catch.

Generator

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

reactrails.com

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stereodenis picture stereodenis  路  9Comments

justin808 picture justin808  路  4Comments

hoenth picture hoenth  路  4Comments

hakunin picture hakunin  路  3Comments

robwise picture robwise  路  3Comments