middleman-dotenv icon indicating copy to clipboard operation
middleman-dotenv copied to clipboard

env set in development environment always prevail

Open jimmychu0807 opened this issue 8 years ago • 1 comments

It seems middleman will always load a development environment first, and then the target environment, be it a :build or :production

So even with the following code block in config.rb

configure :development do
  puts "environment: #{app.environment}"
  activate :dotenv, env: '.env.development'
  p ENV
end

configure :production do
  puts "environment: #{app.environment}"
  activate :dotenv, env: '.env.production'
  p ENV
end

with .env.* define the same variable with different values, the setting in development environment prevails.

If one variable is defined in development but not in production, it is also exposed in production environment.

jimmychu0807 avatar Jun 21 '17 02:06 jimmychu0807

@karlfreeman This looks like it can be solved by using ::Dotenv.overload instead of ::Dotenv.load This way the values loaded from the last target built are the values used. load will not overwrite the original environment variables when the first build is triggered.

johnsaltarelli avatar Jul 09 '17 03:07 johnsaltarelli