source: frontend/node_modules/react-scripts/config/paths.js@ cdcff72

Last change on this file since cdcff72 was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 5.6 KB
Line 
1// @remove-on-eject-begin
2/**
3 * Copyright (c) 2015-present, Facebook, Inc.
4 *
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8// @remove-on-eject-end
9'use strict';
10
11const path = require('path');
12const fs = require('fs');
13const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
14
15// Make sure any symlinks in the project folder are resolved:
16// https://github.com/facebook/create-react-app/issues/637
17const appDirectory = fs.realpathSync(process.cwd());
18const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
19
20// We use `PUBLIC_URL` environment variable or "homepage" field to infer
21// "public path" at which the app is served.
22// webpack needs to know it to put the right <script> hrefs into HTML even in
23// single-page apps that may serve index.html for nested URLs like /todos/42.
24// We can't use a relative path in HTML because we don't want to load something
25// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
26const publicUrlOrPath = getPublicUrlOrPath(
27 process.env.NODE_ENV === 'development',
28 require(resolveApp('package.json')).homepage,
29 process.env.PUBLIC_URL
30);
31
32const buildPath = process.env.BUILD_PATH || 'build';
33
34const 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// Resolve file paths in the same order as webpack
49const 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// config after eject: we're in ./config/
62module.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 appWebpackCache: resolveApp('node_modules/.cache'),
78 appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
79 swSrc: resolveModule(resolveApp, 'src/service-worker'),
80 publicUrlOrPath,
81};
82
83// @remove-on-eject-begin
84const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
85
86// config before eject: we're in ./node_modules/react-scripts/config/
87module.exports = {
88 dotenv: resolveApp('.env'),
89 appPath: resolveApp('.'),
90 appBuild: resolveApp(buildPath),
91 appPublic: resolveApp('public'),
92 appHtml: resolveApp('public/index.html'),
93 appIndexJs: resolveModule(resolveApp, 'src/index'),
94 appPackageJson: resolveApp('package.json'),
95 appSrc: resolveApp('src'),
96 appTsConfig: resolveApp('tsconfig.json'),
97 appJsConfig: resolveApp('jsconfig.json'),
98 yarnLockFile: resolveApp('yarn.lock'),
99 testsSetup: resolveModule(resolveApp, 'src/setupTests'),
100 proxySetup: resolveApp('src/setupProxy.js'),
101 appNodeModules: resolveApp('node_modules'),
102 appWebpackCache: resolveApp('node_modules/.cache'),
103 appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
104 swSrc: resolveModule(resolveApp, 'src/service-worker'),
105 publicUrlOrPath,
106 // These properties only exist before ejecting:
107 ownPath: resolveOwn('.'),
108 ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
109 appTypeDeclarations: resolveApp('src/react-app-env.d.ts'),
110 ownTypeDeclarations: resolveOwn('lib/react-app.d.ts'),
111};
112
113const ownPackageJson = require('../package.json');
114const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
115const reactScriptsLinked =
116 fs.existsSync(reactScriptsPath) &&
117 fs.lstatSync(reactScriptsPath).isSymbolicLink();
118
119// config before publish: we're in ./packages/react-scripts/config/
120if (
121 !reactScriptsLinked &&
122 __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
123) {
124 const templatePath = '../cra-template/template';
125 module.exports = {
126 dotenv: resolveOwn(`${templatePath}/.env`),
127 appPath: resolveApp('.'),
128 appBuild: resolveOwn(path.join('../..', buildPath)),
129 appPublic: resolveOwn(`${templatePath}/public`),
130 appHtml: resolveOwn(`${templatePath}/public/index.html`),
131 appIndexJs: resolveModule(resolveOwn, `${templatePath}/src/index`),
132 appPackageJson: resolveOwn('package.json'),
133 appSrc: resolveOwn(`${templatePath}/src`),
134 appTsConfig: resolveOwn(`${templatePath}/tsconfig.json`),
135 appJsConfig: resolveOwn(`${templatePath}/jsconfig.json`),
136 yarnLockFile: resolveOwn(`${templatePath}/yarn.lock`),
137 testsSetup: resolveModule(resolveOwn, `${templatePath}/src/setupTests`),
138 proxySetup: resolveOwn(`${templatePath}/src/setupProxy.js`),
139 appNodeModules: resolveOwn('node_modules'),
140 appWebpackCache: resolveOwn('node_modules/.cache'),
141 appTsBuildInfoFile: resolveOwn('node_modules/.cache/tsconfig.tsbuildinfo'),
142 swSrc: resolveModule(resolveOwn, `${templatePath}/src/service-worker`),
143 publicUrlOrPath,
144 // These properties only exist before ejecting:
145 ownPath: resolveOwn('.'),
146 ownNodeModules: resolveOwn('node_modules'),
147 appTypeDeclarations: resolveOwn(`${templatePath}/src/react-app-env.d.ts`),
148 ownTypeDeclarations: resolveOwn('lib/react-app.d.ts'),
149 };
150}
151// @remove-on-eject-end
152
153module.exports.moduleFileExtensions = moduleFileExtensions;
Note: See TracBrowser for help on using the repository browser.