diff --git a/examples/basic/package.json b/examples/basic/package.json index 015fee7fa..c3cfaa803 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-basic", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "start": "razzle start", @@ -14,6 +14,6 @@ "serialize-javascript": "^1.3.0" }, "devDependencies": { - "razzle": "^0.5.4" + "razzle": "^0.6.0-rc1" } } diff --git a/examples/with-custom-babel-config/package.json b/examples/with-custom-babel-config/package.json index 26828cfa6..815380de9 100644 --- a/examples/with-custom-babel-config/package.json +++ b/examples/with-custom-babel-config/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-with-custom-babel-config", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "start": "razzle start", @@ -16,6 +16,6 @@ }, "devDependencies": { "babel-preset-stage-0": "^6.22.0", - "razzle": "^0.5.4" + "razzle": "^0.6.0-rc1" } } diff --git a/examples/with-inferno/package.json b/examples/with-inferno/package.json index f68bd9390..137005376 100644 --- a/examples/with-inferno/package.json +++ b/examples/with-inferno/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-inferno", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "start": "razzle start", @@ -16,6 +16,6 @@ "devDependencies": { "babel-plugin-inferno": "^2.0.0", "inferno-devtools": "^1.4.2", - "razzle": "^0.5.4" + "razzle": "^0.6.0-rc1" } } diff --git a/examples/with-jest/package.json b/examples/with-jest/package.json index 337d81688..96370a05a 100644 --- a/examples/with-jest/package.json +++ b/examples/with-jest/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-jest", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "start": "razzle start", @@ -17,7 +17,7 @@ "devDependencies": { "babel-jest": "^19.0.0", "jest-cli": "^19.0.2", - "razzle": "^0.5.4", + "razzle": "^0.6.0-rc1", "react-test-renderer": "^15.4.2" }, "jest": { diff --git a/examples/with-preact/package.json b/examples/with-preact/package.json index 03d2317b4..2553f7008 100644 --- a/examples/with-preact/package.json +++ b/examples/with-preact/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-preact", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "start": "razzle start", @@ -14,6 +14,6 @@ }, "devDependencies": { "babel-plugin-transform-react-jsx": "^6.23.0", - "razzle": "^0.5.4" + "razzle": "^0.6.0-rc1" } } diff --git a/examples/with-rax/package.json b/examples/with-rax/package.json index 1755d72ea..b76a32c85 100644 --- a/examples/with-rax/package.json +++ b/examples/with-rax/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-rax", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "start": "razzle start", @@ -19,6 +19,6 @@ "devDependencies": { "babel-preset-es2015": "^6.24.0", "babel-preset-rax": "^0.2.5", - "razzle": "^0.5.4" + "razzle": "^0.6.0-rc1" } } diff --git a/examples/with-reason-react/package.json b/examples/with-reason-react/package.json index 477c2ee44..c3fe8e2cf 100644 --- a/examples/with-reason-react/package.json +++ b/examples/with-reason-react/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-reason-react", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "dev": "npm run js-watch | npm run bsb-watch", @@ -19,6 +19,6 @@ }, "devDependencies": { "bs-platform": "^1.7.3", - "razzle": "^0.5.4" + "razzle": "^0.6.0-rc1" } } diff --git a/examples/with-redux/package.json b/examples/with-redux/package.json index bf686bbe5..53208ac51 100644 --- a/examples/with-redux/package.json +++ b/examples/with-redux/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-with-redux", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "start": "razzle start", @@ -19,6 +19,6 @@ "serialize-javascript": "^1.3.0" }, "devDependencies": { - "razzle": "^0.5.4" + "razzle": "^0.6.0-rc1" } } diff --git a/examples/with-typescript/package.json b/examples/with-typescript/package.json index 6e0ee1bcf..7afb72196 100644 --- a/examples/with-typescript/package.json +++ b/examples/with-typescript/package.json @@ -1,6 +1,6 @@ { "name": "razzle-examples-with-typescript", - "version": "0.5.4", + "version": "0.6.0-rc1", "license": "MIT", "scripts": { "start": "razzle start", @@ -19,7 +19,7 @@ "@types/react-dom": "^15.5.0", "@types/webpack-env": "^1.13.0", "awesome-typescript-loader": "^3.1.3", - "razzle": "^0.5.4", + "razzle": "^0.6.0-rc1", "tslint": "^5.2.0", "tslint-react": "^3.0.0", "typescript": "^2.3.2" diff --git a/lerna.json b/lerna.json index c538842fa..b91278f31 100644 --- a/lerna.json +++ b/lerna.json @@ -5,7 +5,7 @@ "examples/*" ], "npmClient": "yarn", - "version": "0.5.4", + "version": "0.6.0-rc1", "changelog": { "repo": "jaredpalmer/razzle", "labels": { diff --git a/packages/razzle/config/env.js b/packages/razzle/config/env.js index e5ffeb270..52e34f2b8 100644 --- a/packages/razzle/config/env.js +++ b/packages/razzle/config/env.js @@ -1,6 +1,36 @@ 'use strict'; const paths = require('./paths'); +const fs = require('fs'); + +// Make sure that including paths.js after env.js will read .env variables. +delete require.cache[require.resolve('./paths')]; + +const NODE_ENV = process.env.NODE_ENV; +if (!NODE_ENV) { + throw new Error( + 'The NODE_ENV environment variable is required but was not specified.' + ); +} + +// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use +var dotenvFiles = [ + `${paths.dotenv}.${NODE_ENV}.local`, + `${paths.dotenv}.${NODE_ENV}`, + `${paths.dotenv}.local`, + paths.dotenv, +]; +// Load environment variables from .env* files. Suppress warnings using silent +// if this file is missing. dotenv will never modify any environment variables +// that have already been set. +// https://github.com/motdotla/dotenv +dotenvFiles.forEach(dotenvFile => { + if (fs.existsSync(dotenvFile)) { + require('dotenv').config({ + path: dotenvFile, + }); + } +}); // Grab NODE_ENV and RAZZLE_* environment variables and prepare them to be // injected into the application via DefinePlugin in Webpack configuration. diff --git a/packages/razzle/config/paths.js b/packages/razzle/config/paths.js index a7e4879b3..25d2e299b 100644 --- a/packages/razzle/config/paths.js +++ b/packages/razzle/config/paths.js @@ -29,6 +29,7 @@ function resolveOwn(relativePath) { } module.exports = { + dotenv: resolveApp('.env'), appPath: resolveApp('.'), appBuild: resolveApp('build'), appBuildPublic: resolveApp('build/public'), diff --git a/packages/razzle/package.json b/packages/razzle/package.json index 27279dfcd..fac4b192a 100644 --- a/packages/razzle/package.json +++ b/packages/razzle/package.json @@ -1,6 +1,6 @@ { "name": "razzle", - "version": "0.5.4", + "version": "0.6.0-rc1", "description": "Build isomorphic Javascript applications with ease.", "repository": "git@github.com:jaredpalmer/razzle.git", "author": "jaredpalmer", diff --git a/packages/razzle/scripts/build.js b/packages/razzle/scripts/build.js index 9d17c1515..6446b8812 100755 --- a/packages/razzle/scripts/build.js +++ b/packages/razzle/scripts/build.js @@ -9,7 +9,6 @@ process.on('unhandledRejection', err => { throw err; }); -require('dotenv').config({ silent: true }); const webpack = require('webpack'); const fs = require('fs-extra'); const chalk = require('chalk'); diff --git a/packages/razzle/scripts/start.js b/packages/razzle/scripts/start.js index b857aa263..1b1ea7035 100755 --- a/packages/razzle/scripts/start.js +++ b/packages/razzle/scripts/start.js @@ -1,6 +1,6 @@ #! /usr/bin/env node -require('dotenv').config(); +process.env.NODE_ENV = 'development'; const webpack = require('webpack'); const paths = require('../config/paths'); const printErrors = require('../config/printErrors');