You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

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