paths.js 2.26 KB
Newer Older
1
// @remove-on-eject-begin
2
3
4
5
6
7
8
9
/**
 * 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.
 */
10
// @remove-on-eject-end
11
12
13

var path = require('path');

14
15
16
17
18
19
20
21
22
23
24
25
// We support resolving modules according to NODE_PATH.
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.
// It works just like NODE_PATH in Node:
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
// We will export `nodePaths` as an array of absolute paths.
// It will then be used by Webpack (and potentially other tools).
var nodePaths = (process.env.NODE_PATH || '')
  .split(process.platform === 'win32' ? ';' : ':')
  .filter(Boolean)
  .map(p => path.resolve(p));

26
27
28
function resolveApp(relativePath) {
  return path.resolve(relativePath);
}
29

30
31
32
33
34
35
36
// config after eject: we're in ./config/
module.exports = {
  appBuild: resolveApp('build'),
  appHtml: resolveApp('index.html'),
  appPackageJson: resolveApp('package.json'),
  appSrc: resolveApp('src'),
  appNodeModules: resolveApp('node_modules'),
37
38
  ownNodeModules: resolveApp('node_modules'),
  nodePaths: nodePaths
39
};
40

41
// @remove-on-eject-begin
42
function resolveOwn(relativePath) {
43
44
  return path.resolve(__dirname, relativePath);
}
45

46
47
48
49
50
51
52
53
// config before eject: we're in ./node_modules/react-scripts/config/
module.exports = {
  appBuild: resolveApp('build'),
  appHtml: resolveApp('index.html'),
  appPackageJson: resolveApp('package.json'),
  appSrc: resolveApp('src'),
  appNodeModules: resolveApp('node_modules'),
  // this is empty with npm3 but node resolution searches higher anyway:
54
55
  ownNodeModules: resolveOwn('../node_modules'),
  nodePaths: nodePaths
56
57
};
// @remove-on-eject-end
58

59
60
61
62
63
64
65
// @remove-on-publish-begin
module.exports = {
  appBuild: resolveOwn('../build'),
  appHtml: resolveOwn('../template/index.html'),
  appPackageJson: resolveOwn('../package.json'),
  appSrc: resolveOwn('../template/src'),
  appNodeModules: resolveOwn('../node_modules'),
66
67
  ownNodeModules: resolveOwn('../node_modules'),
  nodePaths: nodePaths
68
69
};
// @remove-on-publish-end