1. 'use strict';
    
  2. 
    
  3. const path = require('path');
    
  4. const fs = require('fs');
    
  5. const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
    
  6. 
    
  7. // Make sure any symlinks in the project folder are resolved:
    
  8. // https://github.com/facebook/create-react-app/issues/637
    
  9. const appDirectory = fs.realpathSync(process.cwd());
    
  10. const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
    
  11. 
    
  12. // We use `PUBLIC_URL` environment variable or "homepage" field to infer
    
  13. // "public path" at which the app is served.
    
  14. // webpack needs to know it to put the right <script> hrefs into HTML even in
    
  15. // single-page apps that may serve index.html for nested URLs like /todos/42.
    
  16. // We can't use a relative path in HTML because we don't want to load something
    
  17. // like /todos/42/static/js/bundle.7289d.js. We have to know the root.
    
  18. const publicUrlOrPath = getPublicUrlOrPath(
    
  19.   process.env.NODE_ENV === 'development',
    
  20.   require(resolveApp('package.json')).homepage,
    
  21.   process.env.PUBLIC_URL
    
  22. );
    
  23. 
    
  24. const buildPath = process.env.BUILD_PATH || 'build';
    
  25. 
    
  26. const moduleFileExtensions = [
    
  27.   'web.mjs',
    
  28.   'mjs',
    
  29.   'web.js',
    
  30.   'js',
    
  31.   'web.ts',
    
  32.   'ts',
    
  33.   'web.tsx',
    
  34.   'tsx',
    
  35.   'json',
    
  36.   'web.jsx',
    
  37.   'jsx',
    
  38. ];
    
  39. 
    
  40. // Resolve file paths in the same order as webpack
    
  41. const resolveModule = (resolveFn, filePath) => {
    
  42.   const extension = moduleFileExtensions.find(extension =>
    
  43.     fs.existsSync(resolveFn(`${filePath}.${extension}`))
    
  44.   );
    
  45. 
    
  46.   if (extension) {
    
  47.     return resolveFn(`${filePath}.${extension}`);
    
  48.   }
    
  49. 
    
  50.   return resolveFn(`${filePath}.js`);
    
  51. };
    
  52. 
    
  53. // config after eject: we're in ./config/
    
  54. module.exports = {
    
  55.   dotenv: resolveApp('.env'),
    
  56.   appPath: resolveApp('.'),
    
  57.   appBuild: resolveApp(buildPath),
    
  58.   appPublic: resolveApp('public'),
    
  59.   appIndexJs: resolveModule(resolveApp, 'src/index'),
    
  60.   appPackageJson: resolveApp('package.json'),
    
  61.   appSrc: resolveApp('src'),
    
  62.   appTsConfig: resolveApp('tsconfig.json'),
    
  63.   appJsConfig: resolveApp('jsconfig.json'),
    
  64.   yarnLockFile: resolveApp('yarn.lock'),
    
  65.   testsSetup: resolveModule(resolveApp, 'src/setupTests'),
    
  66.   appNodeModules: resolveApp('node_modules'),
    
  67.   appWebpackCache: resolveApp('node_modules/.cache'),
    
  68.   appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
    
  69.   swSrc: resolveModule(resolveApp, 'src/service-worker'),
    
  70.   publicUrlOrPath,
    
  71. };
    
  72. 
    
  73. module.exports.moduleFileExtensions = moduleFileExtensions;