2018-05-13 09:57:47 +03:00
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const url = require('url');
|
|
|
|
|
|
|
|
// Make sure any symlinks in the project folder are resolved:
|
|
|
|
// https://github.com/facebookincubator/create-react-app/issues/637
|
|
|
|
const appDirectory = fs.realpathSync(process.cwd());
|
2018-08-26 01:00:53 +03:00
|
|
|
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
|
2018-05-13 09:57:47 +03:00
|
|
|
|
|
|
|
const envPublicUrl = process.env.PUBLIC_URL;
|
|
|
|
|
|
|
|
function ensureSlash(path, needsSlash) {
|
|
|
|
const hasSlash = path.endsWith('/');
|
2018-08-26 01:00:53 +03:00
|
|
|
|
2018-05-13 09:57:47 +03:00
|
|
|
if (hasSlash && !needsSlash) {
|
|
|
|
return path.substr(path, path.length - 1);
|
|
|
|
} else if (!hasSlash && needsSlash) {
|
|
|
|
return `${path}/`;
|
|
|
|
}
|
2018-08-26 01:00:53 +03:00
|
|
|
|
|
|
|
return path;
|
2018-05-13 09:57:47 +03:00
|
|
|
}
|
|
|
|
|
2018-08-26 01:00:53 +03:00
|
|
|
const getPublicUrl = (appPackageJson) =>
|
2018-05-13 09:57:47 +03:00
|
|
|
envPublicUrl || require(appPackageJson).homepage;
|
|
|
|
|
|
|
|
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
|
|
|
// "public path" at which the app is served.
|
|
|
|
// Webpack needs to know it to put the right <script> hrefs into HTML even in
|
|
|
|
// single-page apps that may serve index.html for nested URLs like /todos/42.
|
|
|
|
// We can't use a relative path in HTML because we don't want to load something
|
|
|
|
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
|
|
|
|
function getServedPath(appPackageJson) {
|
|
|
|
const publicUrl = getPublicUrl(appPackageJson);
|
|
|
|
const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
2018-08-26 01:00:53 +03:00
|
|
|
|
2018-05-13 09:57:47 +03:00
|
|
|
return ensureSlash(servedUrl, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// config after eject: we're in ./config/
|
|
|
|
module.exports = {
|
|
|
|
dotenv: resolveApp('.env'),
|
|
|
|
appBuild: resolveApp('build'),
|
|
|
|
appPublic: resolveApp('public'),
|
|
|
|
appHtml: resolveApp('public/index.html'),
|
|
|
|
appIndexJs: resolveApp('src/index.js'),
|
|
|
|
appPackageJson: resolveApp('package.json'),
|
|
|
|
appSrc: resolveApp('src'),
|
|
|
|
yarnLockFile: resolveApp('yarn.lock'),
|
|
|
|
testsSetup: resolveApp('src/setupTests.js'),
|
|
|
|
appNodeModules: resolveApp('node_modules'),
|
|
|
|
publicUrl: getPublicUrl(resolveApp('package.json')),
|
|
|
|
servedPath: getServedPath(resolveApp('package.json')),
|
|
|
|
};
|