mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-06-15 18:08:15 +08:00
* Symlink-friendly path resolution I was having difficulties using a local copy of `react-scripts` and `npm link`ing it into a real world project. This change resolves paths relative to the current working directory (that is, most likely the directory of the app) rather than assuming a certain directory structure. * Fix relative paths in post-eject case because I'm an idiot * Renamed resolveLib to resolveOwn
69 lines
2.2 KiB
JavaScript
69 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
// TODO: we can split this file into several files (pre-eject, post-eject, test)
|
|
// and use those instead. This way we don't need to branch here.
|
|
|
|
var path = require('path');
|
|
|
|
// True after ejecting, false when used as a dependency
|
|
var isEjected = (
|
|
path.resolve(path.join(__dirname, '..')) ===
|
|
path.resolve(process.cwd())
|
|
);
|
|
|
|
// Are we developing create-react-app locally?
|
|
var isInCreateReactAppSource = (
|
|
process.argv.some(arg => arg.indexOf('--debug-template') > -1)
|
|
);
|
|
|
|
function resolveOwn(relativePath) {
|
|
return path.resolve(__dirname, relativePath);
|
|
}
|
|
|
|
function resolveApp(relativePath) {
|
|
return path.resolve(relativePath);
|
|
}
|
|
|
|
if (isInCreateReactAppSource) {
|
|
// create-react-app development: we're in ./config/
|
|
module.exports = {
|
|
appBuild: resolveOwn('../build'),
|
|
appHtml: resolveOwn('../template/index.html'),
|
|
appFavicon: resolveOwn('../template/favicon.ico'),
|
|
appPackageJson: resolveOwn('../package.json'),
|
|
appSrc: resolveOwn('../template/src'),
|
|
appNodeModules: resolveOwn('../node_modules'),
|
|
ownNodeModules: resolveOwn('../node_modules')
|
|
};
|
|
} else if (!isEjected) {
|
|
// before eject: we're in ./node_modules/react-scripts/config/
|
|
module.exports = {
|
|
appBuild: resolveApp('build'),
|
|
appHtml: resolveApp('index.html'),
|
|
appFavicon: resolveApp('favicon.ico'),
|
|
appPackageJson: resolveApp('package.json'),
|
|
appSrc: resolveApp('src'),
|
|
appNodeModules: resolveApp('node_modules'),
|
|
// this is empty with npm3 but node resolution searches higher anyway:
|
|
ownNodeModules: resolveOwn('../node_modules')
|
|
};
|
|
} else {
|
|
// after eject: we're in ./config/
|
|
module.exports = {
|
|
appBuild: resolveApp('build'),
|
|
appHtml: resolveApp('index.html'),
|
|
appFavicon: resolveApp('favicon.ico'),
|
|
appPackageJson: resolveApp('package.json'),
|
|
appSrc: resolveApp('src'),
|
|
appNodeModules: resolveApp('node_modules'),
|
|
ownNodeModules: resolveApp('node_modules')
|
|
};
|
|
}
|