12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 'use strict';
-
- const fs = require('fs');
- const path = require('path');
- const paths = require('./paths');
-
-
- 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.'
- );
- }
-
-
- var dotenvFiles = [
- `${paths.dotenv}.${NODE_ENV}.local`,
- `${paths.dotenv}.${NODE_ENV}`,
-
-
-
- NODE_ENV !== 'test' && `${paths.dotenv}.local`,
- paths.dotenv,
- ].filter(Boolean);
-
-
-
-
-
-
- dotenvFiles.forEach(dotenvFile => {
- if (fs.existsSync(dotenvFile)) {
- require('dotenv-expand')(
- require('dotenv').config({
- path: dotenvFile,
- })
- );
- }
- });
-
-
-
-
-
-
-
-
-
-
- const appDirectory = fs.realpathSync(process.cwd());
- process.env.NODE_PATH = (process.env.NODE_PATH || '')
- .split(path.delimiter)
- .filter(folder => folder && !path.isAbsolute(folder))
- .map(folder => path.resolve(appDirectory, folder))
- .join(path.delimiter);
-
-
-
- const REACT_APP = /^REACT_APP_/i;
-
- function getClientEnvironment(publicUrl) {
- const raw = Object.keys(process.env)
- .filter(key => REACT_APP.test(key))
- .reduce(
- (env, key) => {
- env[key] = process.env[key];
- return env;
- },
- {
-
-
- NODE_ENV: process.env.NODE_ENV || 'development',
-
-
-
-
- PUBLIC_URL: publicUrl,
- }
- );
-
- const stringified = {
- 'process.env': Object.keys(raw).reduce((env, key) => {
- env[key] = JSON.stringify(raw[key]);
- return env;
- }, {}),
- };
-
- return { raw, stringified };
- }
-
- module.exports = getClientEnvironment;
|