123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- '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;
|