1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | const path = require('path');
|
12 | const fs = require('fs');
|
13 | const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
|
14 |
|
15 |
|
16 |
|
17 | const appDirectory = fs.realpathSync(process.cwd());
|
18 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | const publicUrlOrPath = getPublicUrlOrPath(
|
27 | process.env.NODE_ENV === 'development',
|
28 | require(resolveApp('package.json')).homepage,
|
29 | process.env.PUBLIC_URL
|
30 | );
|
31 |
|
32 | const buildPath = process.env.BUILD_PATH || 'build';
|
33 |
|
34 | const moduleFileExtensions = [
|
35 | 'web.mjs',
|
36 | 'mjs',
|
37 | 'web.js',
|
38 | 'js',
|
39 | 'web.ts',
|
40 | 'ts',
|
41 | 'web.tsx',
|
42 | 'tsx',
|
43 | 'json',
|
44 | 'web.jsx',
|
45 | 'jsx',
|
46 | ];
|
47 |
|
48 |
|
49 | const resolveModule = (resolveFn, filePath) => {
|
50 | const extension = moduleFileExtensions.find(extension =>
|
51 | fs.existsSync(resolveFn(`${filePath}.${extension}`))
|
52 | );
|
53 |
|
54 | if (extension) {
|
55 | return resolveFn(`${filePath}.${extension}`);
|
56 | }
|
57 |
|
58 | return resolveFn(`${filePath}.js`);
|
59 | };
|
60 |
|
61 |
|
62 | module.exports = {
|
63 | dotenv: resolveApp('.env'),
|
64 | appPath: resolveApp('.'),
|
65 | appBuild: resolveApp(buildPath),
|
66 | appPublic: resolveApp('public'),
|
67 | appHtml: resolveApp('public/index.html'),
|
68 | appIndexJs: resolveModule(resolveApp, 'src/index'),
|
69 | appPackageJson: resolveApp('package.json'),
|
70 | appSrc: resolveApp('src'),
|
71 | appTsConfig: resolveApp('tsconfig.json'),
|
72 | appJsConfig: resolveApp('jsconfig.json'),
|
73 | yarnLockFile: resolveApp('yarn.lock'),
|
74 | testsSetup: resolveModule(resolveApp, 'src/setupTests'),
|
75 | proxySetup: resolveApp('src/setupProxy.js'),
|
76 | appNodeModules: resolveApp('node_modules'),
|
77 | swSrc: resolveModule(resolveApp, 'src/service-worker'),
|
78 | publicUrlOrPath,
|
79 | };
|
80 |
|
81 |
|
82 | const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
|
83 |
|
84 |
|
85 | module.exports = {
|
86 | dotenv: resolveApp('.env'),
|
87 | appPath: resolveApp('.'),
|
88 | appBuild: resolveApp(buildPath),
|
89 | appPublic: resolveApp('public'),
|
90 | appHtml: resolveApp('public/index.html'),
|
91 | appIndexJs: resolveModule(resolveApp, 'src/index'),
|
92 | appPackageJson: resolveApp('package.json'),
|
93 | appSrc: resolveApp('src'),
|
94 | appTsConfig: resolveApp('tsconfig.json'),
|
95 | appJsConfig: resolveApp('jsconfig.json'),
|
96 | yarnLockFile: resolveApp('yarn.lock'),
|
97 | testsSetup: resolveModule(resolveApp, 'src/setupTests'),
|
98 | proxySetup: resolveApp('src/setupProxy.js'),
|
99 | appNodeModules: resolveApp('node_modules'),
|
100 | swSrc: resolveModule(resolveApp, 'src/service-worker'),
|
101 | publicUrlOrPath,
|
102 |
|
103 | ownPath: resolveOwn('.'),
|
104 | ownNodeModules: resolveOwn('node_modules'),
|
105 | appTypeDeclarations: resolveApp('src/react-app-env.d.ts'),
|
106 | ownTypeDeclarations: resolveOwn('lib/react-app.d.ts'),
|
107 | };
|
108 |
|
109 | const ownPackageJson = require('../package.json');
|
110 | const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
|
111 | const reactScriptsLinked =
|
112 | fs.existsSync(reactScriptsPath) &&
|
113 | fs.lstatSync(reactScriptsPath).isSymbolicLink();
|
114 |
|
115 |
|
116 | if (
|
117 | !reactScriptsLinked &&
|
118 | __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
|
119 | ) {
|
120 | const templatePath = '../cra-template/template';
|
121 | module.exports = {
|
122 | dotenv: resolveOwn(`${templatePath}/.env`),
|
123 | appPath: resolveApp('.'),
|
124 | appBuild: resolveOwn(path.join('../..', buildPath)),
|
125 | appPublic: resolveOwn(`${templatePath}/public`),
|
126 | appHtml: resolveOwn(`${templatePath}/public/index.html`),
|
127 | appIndexJs: resolveModule(resolveOwn, `${templatePath}/src/index`),
|
128 | appPackageJson: resolveOwn('package.json'),
|
129 | appSrc: resolveOwn(`${templatePath}/src`),
|
130 | appTsConfig: resolveOwn(`${templatePath}/tsconfig.json`),
|
131 | appJsConfig: resolveOwn(`${templatePath}/jsconfig.json`),
|
132 | yarnLockFile: resolveOwn(`${templatePath}/yarn.lock`),
|
133 | testsSetup: resolveModule(resolveOwn, `${templatePath}/src/setupTests`),
|
134 | proxySetup: resolveOwn(`${templatePath}/src/setupProxy.js`),
|
135 | appNodeModules: resolveOwn('node_modules'),
|
136 | swSrc: resolveModule(resolveOwn, `${templatePath}/src/service-worker`),
|
137 | publicUrlOrPath,
|
138 |
|
139 | ownPath: resolveOwn('.'),
|
140 | ownNodeModules: resolveOwn('node_modules'),
|
141 | appTypeDeclarations: resolveOwn(`${templatePath}/src/react-app-env.d.ts`),
|
142 | ownTypeDeclarations: resolveOwn('lib/react-app.d.ts'),
|
143 | };
|
144 | }
|
145 |
|
146 |
|
147 | module.exports.moduleFileExtensions = moduleFileExtensions;
|