1234567891011121314151617181920212223242526272829303132333435363738394041 |
- const path = require('path');
- const fs = require('fs');
- const url = require('url');
- const appDirectory = fs.realpathSync(process.cwd());
- const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
- const envPublicUrl = process.env.PUBLIC_URL;
- function ensureSlash(_path, needsSlash) {
- const hasSlash = _path.endsWith('/');
- if (hasSlash && !needsSlash) {
- return _path.substr(_path, _path.length - 1);
- } else if (!hasSlash && needsSlash) {
- return `${_path}/`;
- }
- return _path;
- }
- const getPublicUrl = appPackageJson => envPublicUrl || require(appPackageJson).homepage;
- function getServedPath(appPackageJson) {
- const publicUrl = getPublicUrl(appPackageJson);
- const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
- return ensureSlash(servedUrl, true);
- }
- module.exports = {
- dotenv: resolveApp('.env'),
- appBuild: resolveApp('build'),
- appDist: resolveApp('dist'),
- appPublic: resolveApp('public'),
- appHtml: resolveApp('public/index.html'),
- appIndexJs: resolveApp('src/index.js'),
- appPackageJson: resolveApp('package.json'),
- appSrc: resolveApp('src'),
- yarnLockFile: resolveApp('yarn.lock'),
- appNodeModules: resolveApp('node_modules'),
- publicUrl: getPublicUrl(resolveApp('package.json')),
- servedPath: getServedPath(resolveApp('package.json')),
- };
|