3const path = require('path');
4const fs = require('fs');
5const url = require('url');
7// Make sure any symlinks in the project folder are resolved:
8// https://github.com/facebook/create-react-app/issues/637
9const appDirectory = fs.realpathSync(process.cwd());
10const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
12const envPublicUrl = process.env.PUBLIC_URL;
14function ensureSlash(inputPath, needsSlash) {
15 const hasSlash = inputPath.endsWith('/');
16 if (hasSlash && !needsSlash) {
17 return inputPath.substr(0, inputPath.length - 1);
18 } else if (!hasSlash && needsSlash) {
19 return `${inputPath}/`;
25const getPublicUrl = appPackageJson =>
26 envPublicUrl || require(appPackageJson).homepage;
28// We use `PUBLIC_URL` environment variable or "homepage" field to infer
29// "public path" at which the app is served.
30// Webpack needs to know it to put the right <script> hrefs into HTML even in
31// single-page apps that may serve index.html for nested URLs like /todos/42.
32// We can't use a relative path in HTML because we don't want to load something
33// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
34function getServedPath(appPackageJson) {
35 const publicUrl = getPublicUrl(appPackageJson);
37 envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
38 return ensureSlash(servedUrl, true);
41const moduleFileExtensions = [
55// Resolve file paths in the same order as webpack
56const resolveModule = (resolveFn, filePath) => {
57 const extension = moduleFileExtensions.find(extension =>
58 fs.existsSync(resolveFn(`${filePath}.${extension}`))
62 return resolveFn(`${filePath}.${extension}`);
65 return resolveFn(`${filePath}.js`);
68// config after eject: we're in ./config/
70 dotenv: resolveApp('.env'),
71 appPath: resolveApp('.'),
72 appBuild: resolveApp('build'),
73 appPublic: resolveApp('public'),
74 appHtml: resolveApp('public/index.html'),
75 appIndexJs: resolveModule(resolveApp, 'src/index'),
76 appPackageJson: resolveApp('package.json'),
77 appSrc: resolveApp('src'),
78 appTsConfig: resolveApp('tsconfig.json'),
79 appJsConfig: resolveApp('jsconfig.json'),
80 yarnLockFile: resolveApp('yarn.lock'),
81 testsSetup: resolveModule(resolveApp, 'src/setupTests'),
82 proxySetup: resolveApp('src/setupProxy.js'),
83 appNodeModules: resolveApp('node_modules'),
84 publicUrl: getPublicUrl(resolveApp('package.json')),
85 servedPath: getServedPath(resolveApp('package.json')),
90module.exports.moduleFileExtensions = moduleFileExtensions;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list