paths.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.NODE_ENV == 'development' ? 'devbuild' : process.env.BUILD_PATH || 'build'
  21. // process.env.NODE_ENV == 'development' ? 'devbuild' : 'build',
  22. // console.log(buildPath)
  23. const moduleFileExtensions = [
  24. 'web.mjs',
  25. 'mjs',
  26. 'web.js',
  27. 'js',
  28. 'web.ts',
  29. 'ts',
  30. 'web.tsx',
  31. 'tsx',
  32. 'json',
  33. 'web.jsx',
  34. 'jsx',
  35. ];
  36. // Resolve file paths in the same order as webpack
  37. const resolveModule = (resolveFn, filePath) => {
  38. const extension = moduleFileExtensions.find(extension =>
  39. fs.existsSync(resolveFn(`${filePath}.${extension}`))
  40. );
  41. if (extension) {
  42. return resolveFn(`${filePath}.${extension}`);
  43. }
  44. return resolveFn(`${filePath}.js`);
  45. };
  46. // config after eject: we're in ./config/
  47. module.exports = {
  48. dotenv: resolveApp('.env'),
  49. appPath: resolveApp('.'),
  50. appBuild: resolveApp(buildPath),
  51. appPublic: resolveApp('public'),
  52. appHtml: resolveApp('public/index.html'),
  53. appIndexJs: resolveModule(resolveApp, 'src/index'),
  54. appPackageJson: resolveApp('package.json'),
  55. appSrc: resolveApp('src'),
  56. appTsConfig: resolveApp('tsconfig.json'),
  57. appJsConfig: resolveApp('jsconfig.json'),
  58. yarnLockFile: resolveApp('yarn.lock'),
  59. testsSetup: resolveModule(resolveApp, 'src/setupTests'),
  60. proxySetup: resolveApp('src/setupProxy.js'),
  61. appNodeModules: resolveApp('node_modules'),
  62. swSrc: resolveModule(resolveApp, 'src/service-worker'),
  63. publicUrlOrPath,
  64. };
  65. module.exports.moduleFileExtensions = moduleFileExtensions;