babel-plugin-dotenv
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -18,6 +18,9 @@ var dotEnv = require('dotenv'); | ||
var configDir = options.configDir ? options.configDir : './'; | ||
var configFile = options.filename ? options.filename : '.env'; | ||
if (path.node.source.value === options.replacedModuleName) { | ||
var config = dotEnv.config({ path: sysPath.join(configDir, '.env'), silent: true }) || {}; | ||
var platformPath = (process.env.BABEL_ENV === 'development' || process.env.BABEL_ENV === undefined) ? '.env.development' : '.env.production'; | ||
var config = dotEnv.config({ path: sysPath.join(configDir, configFile), silent: true }) || {}; | ||
var platformPath = (process.env.BABEL_ENV === 'development' || process.env.BABEL_ENV === undefined) | ||
? configFile + '.development' | ||
: configFile + '.production'; | ||
var config = Object.assign(config, dotEnv.config({ path: sysPath.join(configDir, platformPath), silent: true })); | ||
@@ -33,3 +36,3 @@ | ||
if(!config[importedId]) { | ||
throw path.get('specifiers')[idx].buildCodeFrameError('Try to import dotenv variable "' + importedId + '" which is not defined in any .env files.') | ||
throw path.get('specifiers')[idx].buildCodeFrameError('Try to import dotenv variable "' + importedId + '" which is not defined in any ' + configFile + ' files.') | ||
} | ||
@@ -36,0 +39,0 @@ |
{ | ||
"name": "babel-plugin-dotenv", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Load environment variables from .env file using import statement", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -40,2 +40,7 @@ var babel = require("babel-core"); | ||
it('should load custom env file "build.env" and its overwrites', function(){ | ||
var result = babel.transformFileSync('test/fixtures/filename/source.js') | ||
expect(result.code).to.be('\'use strict\';\n\nconsole.log(\'abc123456\');\nconsole.log(\'userdonthavename123456\');') | ||
}) | ||
it('should load let .env.production overwrite .env', function(){ | ||
@@ -42,0 +47,0 @@ process.env['BABEL_ENV'] = 'production'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8552
32
112