├── .gitignore ├── .npmignore ├── babel-plugin-dotenv ├── .gitignore ├── test │ ├── fixtures │ │ ├── prod-env │ │ │ ├── .env.production │ │ │ ├── .env │ │ │ ├── .env.development │ │ │ ├── source.js │ │ │ └── .babelrc │ │ ├── as-alias │ │ │ ├── .env │ │ │ ├── source.js │ │ │ └── .babelrc │ │ ├── default │ │ │ ├── .env │ │ │ ├── source.js │ │ │ └── .babelrc │ │ ├── dev-env │ │ │ ├── .env │ │ │ ├── .env.development │ │ │ ├── source.js │ │ │ └── .babelrc │ │ ├── filename │ │ │ ├── .env │ │ │ ├── .env.development │ │ │ ├── build.env │ │ │ ├── build.env.development │ │ │ ├── source.js │ │ │ └── .babelrc │ │ ├── default-imported │ │ │ ├── source.js │ │ │ └── .babelrc │ │ ├── variable-not-exist │ │ │ ├── source.js │ │ │ └── .babelrc │ │ ├── empty-values │ │ │ ├── .env │ │ │ ├── source.js │ │ │ └── .babelrc │ │ └── replaced-module-name-not-provided │ │ │ ├── source.js │ │ │ └── .babelrc │ └── test.js ├── README.md ├── package.json └── index.js ├── error.png ├── index.js ├── package.json ├── LICENSE ├── CHANGELOG.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | error.png 2 | /babel-plugin-dotenv 3 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /coverage 3 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/prod-env/.env.production: -------------------------------------------------------------------------------- 1 | DEV_USERNAME=foobar 2 | -------------------------------------------------------------------------------- /error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zetachang/react-native-dotenv/HEAD/error.png -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/as-alias/.env: -------------------------------------------------------------------------------- 1 | API_KEY=abc123 2 | DEV_USERNAME=username 3 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/default/.env: -------------------------------------------------------------------------------- 1 | API_KEY=abc123 2 | DEV_USERNAME=username 3 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/dev-env/.env: -------------------------------------------------------------------------------- 1 | API_KEY=abc123 2 | DEV_USERNAME=username 3 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/dev-env/.env.development: -------------------------------------------------------------------------------- 1 | DEV_USERNAME=userdonthavename 2 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/filename/.env: -------------------------------------------------------------------------------- 1 | API_KEY=abc123 2 | DEV_USERNAME=username 3 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/filename/.env.development: -------------------------------------------------------------------------------- 1 | DEV_USERNAME=userdonthavename 2 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/prod-env/.env: -------------------------------------------------------------------------------- 1 | API_KEY=abc123 2 | DEV_USERNAME=username 3 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/prod-env/.env.development: -------------------------------------------------------------------------------- 1 | DEV_USERNAME=userdonthavename 2 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/default-imported/source.js: -------------------------------------------------------------------------------- 1 | import config from 'babel-dotenv'; 2 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/variable-not-exist/source.js: -------------------------------------------------------------------------------- 1 | import { foo } from "babel-dotenv"; 2 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/filename/build.env: -------------------------------------------------------------------------------- 1 | API_KEY=abc123456 2 | DEV_USERNAME=username123456 3 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/filename/build.env.development: -------------------------------------------------------------------------------- 1 | DEV_USERNAME=userdonthavename123456 2 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/empty-values/.env: -------------------------------------------------------------------------------- 1 | API_KEY=abc123 2 | DEV_USERNAME=username 3 | DEV_PASSWORD= 4 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/replaced-module-name-not-provided/source.js: -------------------------------------------------------------------------------- 1 | import whatever, { foo, bar } from 'fancy-dotenv' 2 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/as-alias/source.js: -------------------------------------------------------------------------------- 1 | import { API_KEY as key, DEV_USERNAME as username } from 'babel-dotenv'; 2 | var a = key; 3 | var b = username; 4 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/default/source.js: -------------------------------------------------------------------------------- 1 | import { API_KEY, DEV_USERNAME } from 'babel-dotenv'; 2 | console.log(API_KEY); 3 | console.log(DEV_USERNAME); 4 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/dev-env/source.js: -------------------------------------------------------------------------------- 1 | import { API_KEY, DEV_USERNAME } from 'babel-dotenv'; 2 | console.log(API_KEY); 3 | console.log(DEV_USERNAME); 4 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/filename/source.js: -------------------------------------------------------------------------------- 1 | import { API_KEY, DEV_USERNAME } from 'babel-dotenv'; 2 | console.log(API_KEY); 3 | console.log(DEV_USERNAME); 4 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/prod-env/source.js: -------------------------------------------------------------------------------- 1 | import { API_KEY, DEV_USERNAME } from 'babel-dotenv'; 2 | console.log(API_KEY); 3 | console.log(DEV_USERNAME); 4 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/replaced-module-name-not-provided/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | "../../../" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/empty-values/source.js: -------------------------------------------------------------------------------- 1 | import { API_KEY, DEV_USERNAME, DEV_PASSWORD } from 'babel-dotenv'; 2 | console.log(API_KEY); 3 | console.log(DEV_USERNAME); 4 | console.log(DEV_PASSWORD); 5 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/default-imported/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | ["../../../", { "replacedModuleName": "babel-dotenv"}] 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/variable-not-exist/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | ["../../../", { "replacedModuleName": "babel-dotenv"}] 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | module.exports = () => ({ 4 | plugins: [ 5 | [require('babel-plugin-dotenv'), { 6 | replacedModuleName: 'react-native-dotenv', 7 | configDir: path.resolve(__dirname, "../../") 8 | }], 9 | ], 10 | }); 11 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/default/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | ["../../../", { 5 | "replacedModuleName": "babel-dotenv", 6 | "configDir": "test/fixtures/default" 7 | }] 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/dev-env/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | ["../../../", { 5 | "replacedModuleName": "babel-dotenv", 6 | "configDir": "test/fixtures/dev-env" 7 | }], 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/as-alias/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | ["../../../", { 5 | "replacedModuleName": "babel-dotenv", 6 | "configDir": "test/fixtures/as-alias" 7 | }], 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/prod-env/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | ["../../../", { 5 | "replacedModuleName": "babel-dotenv", 6 | "configDir": "test/fixtures/prod-env" 7 | }], 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/empty-values/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | ["../../../", { 5 | "replacedModuleName": "babel-dotenv", 6 | "configDir": "test/fixtures/empty-values" 7 | }], 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/fixtures/filename/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "babel-plugin-transform-es2015-modules-commonjs", 4 | ["../../../", { 5 | "replacedModuleName": "babel-dotenv", 6 | "configDir": "test/fixtures/filename", 7 | "filename": "build.env" 8 | }] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-dotenv", 3 | "version": "0.2.0", 4 | "description": "A Babel preset let you `import` application configs from **.env** file (zero runtime dependency)", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "cd babel-plugin-dotenv && npm install && npm test" 8 | }, 9 | "keywords": [ 10 | "dotenv", 11 | "react-native" 12 | ], 13 | "author": "David Chang", 14 | "license": "MIT", 15 | "dependencies": { 16 | "babel-plugin-dotenv": "0.1.1" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/README.md: -------------------------------------------------------------------------------- 1 | # babel-plugin-dotenv 2 | 3 | Loads environment variables from a .env file through `import` statement. 4 | 5 | ## Installation 6 | 7 | ```sh 8 | $ npm install babel-plugin-dotenv 9 | ``` 10 | 11 | ## Usage 12 | 13 | **.babelrc** 14 | 15 | ```json 16 | { 17 | "plugins": [["babel-plugin-dotenv", { 18 | "replacedModuleName": "babel-dotenv" 19 | }]] 20 | } 21 | ``` 22 | 23 | **.env** 24 | 25 | ``` 26 | DB_HOST=localhost 27 | DB_USER=root 28 | DB_PASS=s1mpl3 29 | ``` 30 | 31 | In **whatever.js** 32 | 33 | ```js 34 | import { DB_HOST, DB_USER, DB_PASS } from "babel-dotenv" 35 | db.connect({ 36 | host: DB_HOST, 37 | username: DB_USER, 38 | password: DB_PASS 39 | }); 40 | ``` 41 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-dotenv", 3 | "version": "0.1.1", 4 | "description": "Load environment variables from .env file using import statement", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha", 8 | "coverage": "istanbul cover _mocha -- -R spec" 9 | }, 10 | "keywords": [ 11 | "dotenv", 12 | "babel-plugin" 13 | ], 14 | "dependencies": { 15 | "dotenv": "^2.0.0" 16 | }, 17 | "devDependencies": { 18 | "babel-core": "^6.14.0", 19 | "babel-plugin-transform-es2015-modules-commonjs": "^6.14.0", 20 | "babel-runtime": "^5.0.0", 21 | "expect.js": "^0.3.1", 22 | "istanbul": "^0.4.5", 23 | "mocha": "^3.0.2" 24 | }, 25 | "author": "David Chang", 26 | "license": "MIT" 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Yi-Cheng Chang (http://github.com/zetachang) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Changes are grouped as follows: 4 | - **Added** for new features. 5 | - **Changed** for changes in existing functionality. 6 | - **Deprecated** for once-stable features to be removed in upcoming releases. 7 | - **Removed** for deprecated features removed in this release. 8 | - **Fixed** for any bug fixes. 9 | - **Security** to invite users to upgrade in case of vulnerabilities. 10 | 11 | 17 | 18 | ## [0.2.0] - 2018-7-17 19 | 20 | ### Fixed 21 | 22 | - Compatibility with RN 0.56 (Babel 7) (#42) 23 | 24 | ## [0.1.1] - 2018-1-14 25 | 26 | ### Fixed 27 | 28 | - Empty env is treated as env not found. (#25) 29 | 30 | ## [0.1.0] - 2017-7-9 31 | 32 | ### Fixed 33 | 34 | - Compatibility with RN 0.46+ (#21) 35 | 36 | ### Added 37 | 38 | - Add filename config to allow user to custom filename of .env file (#16) 39 | 40 | ## [0.0.4] - 2017-4-4 41 | 42 | ### Fixed 43 | 44 | - Misleading not found errors is shown (#14) 45 | 46 | ## [0.0.3] - 2017-1-9 47 | 48 | ### Fixed 49 | 50 | - Sometimes .env file could not be found. (#3) 51 | - Some of dotenv warnings are correctly ignored now, thanks @levity! (#4) 52 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/index.js: -------------------------------------------------------------------------------- 1 | var dotEnv = require('dotenv'); 2 | var fs = require('fs'); 3 | var sysPath = require('path'); 4 | var process = require('process'); 5 | 6 | module.exports = function (data) { 7 | var t = data.types; 8 | 9 | return { 10 | visitor: { 11 | ImportDeclaration: function(path, state) { 12 | var options = state.opts; 13 | 14 | if (options.replacedModuleName === undefined) 15 | return; 16 | 17 | var configDir = options.configDir ? options.configDir : './'; 18 | var configFile = options.filename ? options.filename : '.env'; 19 | 20 | if (path.node.source.value === options.replacedModuleName) { 21 | var config = dotEnv.config({ path: sysPath.join(configDir, configFile), silent: true }) || {}; 22 | var platformPath = (process.env.BABEL_ENV === 'development' || process.env.BABEL_ENV === undefined) 23 | ? configFile + '.development' 24 | : configFile + '.production'; 25 | var config = Object.assign(config, dotEnv.config({ path: sysPath.join(configDir, platformPath), silent: true })); 26 | 27 | path.node.specifiers.forEach(function(specifier, idx){ 28 | if (specifier.type === "ImportDefaultSpecifier") { 29 | throw path.get('specifiers')[idx].buildCodeFrameError('Import dotenv as default is not supported.') 30 | } 31 | var importedId = specifier.imported.name 32 | var localId = specifier.local.name; 33 | if(!(config.hasOwnProperty(importedId))) { 34 | throw path.get('specifiers')[idx].buildCodeFrameError('Try to import dotenv variable "' + importedId + '" which is not defined in any ' + configFile + ' files.') 35 | } 36 | 37 | var binding = path.scope.getBinding(localId); 38 | binding.referencePaths.forEach(function(refPath){ 39 | refPath.replaceWith(t.valueToNode(config[importedId])) 40 | }); 41 | }) 42 | 43 | path.remove(); 44 | } 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-dotenv 2 | 3 | Let you `import` environment variables from a **.env** file in React Native, **don't** need any native code integration. 4 | 5 | [![CircleCI](https://circleci.com/gh/zetachang/react-native-dotenv.svg?style=svg)](https://circleci.com/gh/zetachang/react-native-dotenv) 6 | [![npm version](https://img.shields.io/npm/v/react-native-dotenv.svg?style=flat-square)](https://www.npmjs.com/package/react-native-dotenv) 7 | [![npm downloads](https://img.shields.io/npm/dt/react-native-dotenv.svg?style=flat-square)](https://www.npmjs.com/package/react-native-dotenv) 8 | 9 | ## Install 10 | 11 | ```sh 12 | $ npm install react-native-dotenv --save-dev 13 | ``` 14 | 15 | Add the `react-native-dotenv` preset to your **.babelrc** file at the project root. 16 | 17 | ```json 18 | { 19 | "presets": ["module:metro-react-native-babel-preset", "module:react-native-dotenv"] 20 | } 21 | ``` 22 | 23 | If you haven't got **.babelrc** set up for React Native, remember to install `metro-react-native-babel-preset` first. 24 | 25 | ```sh 26 | $ npm install metro-react-native-babel-preset --save-dev 27 | ``` 28 | 29 | ## Usage 30 | 31 | Add your app configuration in an **.env** file. 32 | 33 | ``` 34 | API_KEY=lorem 35 | ANOTHER_CONFIG=foobar 36 | ``` 37 | 38 | Now you can import it in your **.js** file. 39 | 40 | ```js 41 | import { API_KEY, ANOTHER_CONFIG } from 'react-native-dotenv' 42 | 43 | ApiClient.init(API_KEY, ANOTHER_CONFIG) 44 | ``` 45 | 46 | ## How does it work? 47 | 48 | As you can see, it's implemented as a babel plugin. All referenced imported members are replaced as the values specified in the **.env** file. 49 | 50 | The example above will get compiled as below. 51 | 52 | ```js 53 | 54 | ApiClient.init('lorem', 'foobar') 55 | ``` 56 | 57 | ## FAQ 58 | 59 | ### Changes to .env file is not updated 60 | 61 | Manually edit the file importing `react-native-dotenv` by either adding an empty line or whitespace will work. 62 | 63 | ### Can I use different **.env** settings for production ? 64 | 65 | Yes, simply create a separate **.env.production** file and the default release process of react-native will pickup the right config. 66 | 67 | #### iOS 68 | 69 | You can use the **Release** configuration to launch the Simulator. (Only supported in RN v0.39+) 70 | 71 | ``` 72 | react-native run-ios --configuration Release 73 | ``` 74 | #### Android 75 | 76 | 1. `Command⌘` + `M` to launch the developer menu in Android emulator. 77 | 2. Tap **DevSettings**. 78 | 3. Toggle **JS Dev Mode**. 79 | 80 | ### Can I have more than `production` & `development` environment configs? 81 | 82 | Sadly, it's not available so far. One of the workaround is generating **.env** file before triggering RN's bundle script automatically using either shell script or your own custom build pipeline. 83 | 84 | ## Contact 85 | 86 | [David Chang](http://github.com/zetachang) 87 | [@zetachang](https://twitter.com/zetachang) 88 | 89 | ## LICENSE 90 | 91 | MIT License, see LICENSE file for detail. 92 | -------------------------------------------------------------------------------- /babel-plugin-dotenv/test/test.js: -------------------------------------------------------------------------------- 1 | var babel = require("babel-core"); 2 | var expect = require('expect.js'); 3 | var process = require('process'); 4 | 5 | var createPluginsWithConfigDir = function(configDir) { 6 | return ['babel-plugin-transform-es2015-modules-commonjs', ['../../../', 7 | { 8 | replacedModuleName: 'babel-dotenv', 9 | configDir: configDir, 10 | }]]; 11 | } 12 | 13 | describe('myself in some tests', function() { 14 | it('should throw if variable not exist', function() { 15 | expect(function(){ 16 | babel.transformFileSync('test/fixtures/variable-not-exist/source.js') 17 | }).to.throwException(function (e) { 18 | expect(e.message).to.contain("Try to import dotenv variable \"foo\" which is not defined in any .env files."); 19 | }); 20 | }); 21 | 22 | it('should throw if default is imported', function() { 23 | expect(function(){ 24 | babel.transformFileSync('test/fixtures/default-imported/source.js') 25 | }).to.throwException(function (e) { 26 | expect(e.message).to.contain("Import dotenv as default is not supported."); 27 | }); 28 | }); 29 | 30 | it('should load default env from .env', function(){ 31 | var result = babel.transformFileSync('test/fixtures/default/source.js') 32 | expect(result.code).to.be('\'use strict\';\n\nconsole.log(\'abc123\');\nconsole.log(\'username\');') 33 | }) 34 | 35 | it('should load empty variable as empty string ', function(){ 36 | var result = babel.transformFileSync('test/fixtures/empty-values/source.js') 37 | expect(result.code).to.be('\'use strict\';\n\nconsole.log(\'abc123\');\nconsole.log(\'username\');\nconsole.log(\'\');') 38 | }) 39 | 40 | it('should load let .env.development overwrite .env', function(){ 41 | var result = babel.transformFileSync('test/fixtures/dev-env/source.js') 42 | expect(result.code).to.be('\'use strict\';\n\nconsole.log(\'abc123\');\nconsole.log(\'userdonthavename\');') 43 | }) 44 | 45 | it('should load custom env file "build.env" and its overwrites', function(){ 46 | var result = babel.transformFileSync('test/fixtures/filename/source.js') 47 | expect(result.code).to.be('\'use strict\';\n\nconsole.log(\'abc123456\');\nconsole.log(\'userdonthavename123456\');') 48 | }) 49 | 50 | it('should load let .env.production overwrite .env', function(){ 51 | process.env['BABEL_ENV'] = 'production'; 52 | var result = babel.transformFileSync('test/fixtures/prod-env/source.js') 53 | expect(result.code).to.be('\'use strict\';\n\nconsole.log(\'abc123\');\nconsole.log(\'foobar\');') 54 | process.env['BABEL_ENV'] = undefined; 55 | }) 56 | 57 | it('should support `as alias` import syntax', function(){ 58 | var result = babel.transformFileSync('test/fixtures/as-alias/source.js') 59 | expect(result.code).to.be('\'use strict\';\n\nvar a = \'abc123\';\nvar b = \'username\';') 60 | }) 61 | 62 | it('should do nothing if no `replacedModuleName` provided', function(){ 63 | var result = babel.transformFileSync('test/fixtures/replaced-module-name-not-provided/source.js') 64 | expect(result.code).to.be('\'use strict\';\n\nvar _fancyDotenv = require(\'fancy-dotenv\');\n\nvar _fancyDotenv2 = _interopRequireDefault(_fancyDotenv);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }') 65 | }) 66 | }); 67 | --------------------------------------------------------------------------------