Skip to content

Commit

Permalink
Fix CSS Modules FOUC with production build (#296)
Browse files Browse the repository at this point in the history
* Fix CSS Modules FOUC with production build

The production build uses the `lib` folder for built assets. Because CSS
Modules uses the file path to generate the unique hash for the class names,
this causes an inconsistency between the client and server class names, which
causes a Flash Of Unstyled Content (FOUC) in production mode.

* set node_env=production on prod build
  • Loading branch information
kaytcat authored and jchip committed Apr 22, 2017
1 parent 1575492 commit 9c88e44
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module.exports = function () {
new CSSSplitPlugin({ size: 4000, imports: true, preserve: true }),
new webpack.LoaderOptionsPlugin({
options: {
context: Path.resolve(process.cwd(), "client"),
context: Path.resolve(process.cwd(), "src"),
postcss: () => {
return cssModuleSupport ? [atImport, cssnext({
browsers: ["last 2 versions", "ie >= 9", "> 5%"]
Expand Down
3 changes: 2 additions & 1 deletion packages/electrode-archetype-react-app/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const logger = require("../lib/logger");

const support = {
cssModuleHook: (options) => {
const defaultRootDirPath = process.env.NODE_ENV === "production" ? "lib" : "src";
options = options || {};
options.generateScopedName = options.generateScopedName || "[hash:base64]";
options.rootDir = options.rootDir || Path.resolve(process.cwd(), "client");
options.rootDir = options.rootDir || Path.resolve(process.cwd(), defaultRootDirPath);

require("css-modules-require-hook")(options);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"start": "if test \"$NODE_ENV\" = \"production\"; then npm run prod; else gulp dev; fi",
"test": "gulp check",
"coverage": "gulp check",
"prod": "echo 'Starting standalone server in PROD mode'; node ./lib/server/",
"prod": "echo 'Starting standalone server in PROD mode'; NODE_ENV=production node ./lib/server/",
"heroku-postbuild": "gulp build"
},
"dependencies": {
Expand Down

0 comments on commit 9c88e44

Please sign in to comment.