Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment-specific and local .env files #269

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "razzle-examples-basic",
"version": "0.5.4",
"version": "0.6.0-rc1",
"license": "MIT",
"scripts": {
"start": "razzle start",
Expand All @@ -14,6 +14,6 @@
"serialize-javascript": "^1.3.0"
},
"devDependencies": {
"razzle": "^0.5.4"
"razzle": "^0.6.0-rc1"
}
}
4 changes: 2 additions & 2 deletions examples/with-custom-babel-config/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -16,6 +16,6 @@
},
"devDependencies": {
"babel-preset-stage-0": "^6.22.0",
"razzle": "^0.5.4"
"razzle": "^0.6.0-rc1"
}
}
4 changes: 2 additions & 2 deletions examples/with-inferno/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "razzle-examples-inferno",
"version": "0.5.4",
"version": "0.6.0-rc1",
"license": "MIT",
"scripts": {
"start": "razzle start",
Expand All @@ -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"
}
}
4 changes: 2 additions & 2 deletions examples/with-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "razzle-examples-jest",
"version": "0.5.4",
"version": "0.6.0-rc1",
"license": "MIT",
"scripts": {
"start": "razzle start",
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions examples/with-preact/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "razzle-examples-preact",
"version": "0.5.4",
"version": "0.6.0-rc1",
"license": "MIT",
"scripts": {
"start": "razzle start",
Expand All @@ -14,6 +14,6 @@
},
"devDependencies": {
"babel-plugin-transform-react-jsx": "^6.23.0",
"razzle": "^0.5.4"
"razzle": "^0.6.0-rc1"
}
}
4 changes: 2 additions & 2 deletions examples/with-rax/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "razzle-examples-rax",
"version": "0.5.4",
"version": "0.6.0-rc1",
"license": "MIT",
"scripts": {
"start": "razzle start",
Expand All @@ -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"
}
}
4 changes: 2 additions & 2 deletions examples/with-reason-react/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -19,6 +19,6 @@
},
"devDependencies": {
"bs-platform": "^1.7.3",
"razzle": "^0.5.4"
"razzle": "^0.6.0-rc1"
}
}
4 changes: 2 additions & 2 deletions examples/with-redux/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "razzle-examples-with-redux",
"version": "0.5.4",
"version": "0.6.0-rc1",
"license": "MIT",
"scripts": {
"start": "razzle start",
Expand All @@ -19,6 +19,6 @@
"serialize-javascript": "^1.3.0"
},
"devDependencies": {
"razzle": "^0.5.4"
"razzle": "^0.6.0-rc1"
}
}
4 changes: 2 additions & 2 deletions examples/with-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "razzle-examples-with-typescript",
"version": "0.5.4",
"version": "0.6.0-rc1",
"license": "MIT",
"scripts": {
"start": "razzle start",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"examples/*"
],
"npmClient": "yarn",
"version": "0.5.4",
"version": "0.6.0-rc1",
"changelog": {
"repo": "jaredpalmer/razzle",
"labels": {
Expand Down
30 changes: 30 additions & 0 deletions packages/razzle/config/env.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/razzle/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function resolveOwn(relativePath) {
}

module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp('build'),
appBuildPublic: resolveApp('build/public'),
Expand Down
2 changes: 1 addition & 1 deletion packages/razzle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "razzle",
"version": "0.5.4",
"version": "0.6.0-rc1",
"description": "Build isomorphic Javascript applications with ease.",
"repository": "[email protected]:jaredpalmer/razzle.git",
"author": "jaredpalmer",
Expand Down
1 change: 0 additions & 1 deletion packages/razzle/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion packages/razzle/scripts/start.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down