-
Notifications
You must be signed in to change notification settings - Fork 5
/
conf.app.js
87 lines (83 loc) · 2.52 KB
/
conf.app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { resolve } = require('path');
const packageJSON = require('./package.json');
// Some paths have to be normalized when this file is copied over to dist
const inDist = __dirname.endsWith('dist');
const ROOT = resolve(__dirname, (inDist) ? '../' : '');
const DIST = `${ ROOT }/dist`;
const DIST_PRIVATE = `${ DIST }/private`;
const DIST_PUBLIC = `${ DIST }/public`;
const SRC = (inDist) ? DIST_PRIVATE : `${ ROOT }/src`;
const SRC_STATIC = (inDist) ? DIST_PUBLIC : `${ SRC }/static`;
const SRC_MEDIA = `${ SRC_STATIC }/media`;
const PACKAGE_JSON = (inDist) ? `${ DIST }/package.json` : `${ ROOT }/package.json`;
const conf = {
app: {
NAME: packageJSON.name,
VERSION: packageJSON.version,
},
APP_TITLE: 'React SPA (full server)',
clientPaths: {
PUBLIC_URL: '',
MEDIA: '/media',
},
paths: {
APP_INDEX: `${ SRC }/index.js`,
DIST,
DIST_PRIVATE,
DIST_PUBLIC,
FAVICON: `${ SRC_MEDIA }/favicon.png`,
JEST: `${ ROOT }/.jest`,
NODE_MODULES: `${ ROOT }/node_modules`,
PACKAGE_JSON,
ROOT,
SRC,
SRC_STATIC,
},
// Even though `SERVER_PORT` is a number in the package.json, it comes
// through as a String, so cast it back to a number via `+`
PORT: +process.env.npm_package_config_SERVER_PORT,
webpack: {
// Normally WP is only for client code, but we're utilizing the
// `webpack-alias` plugin to simplify out pathing in files. So it's ok to
// have a mixture of public and private paths.
aliases: {
COMPONENTS: `${ SRC }/components`,
CONSTANTS: `${ SRC }/constants`,
DIST_PRIVATE,
DIST_PUBLIC,
ROOT,
ROUTES: `${ SRC }/routes`,
SERVER: `${ SRC }/server`,
SRC,
STATE: `${ SRC }/state`,
UTILS: `${ SRC }/utils`,
},
// The order of the `entries` dictates the order that they're added in the DOM
entries: {
BOOTSTRAP: 'wp_bootstrap',
VENDOR: 'vendor',
APP: 'app',
},
paths: {
OUTPUT: '/dist/public',
},
MANIFEST_NAME: 'assets-manifest.json',
},
};
/**
* Use `resolve` to normalize paths, so that on Windows, something like a
* Webpack loader won't get a path like `C:\some\path/to/something` and not
* apply itself.
*
* @param {Array} keys - An Array of key paths relative to the `conf` Object.
*/
const normalizePaths = (keys) => {
keys.forEach((key) => {
const obj = eval(`conf.${ key }`);
Object.keys(obj).forEach((pathKey) => {
obj[pathKey] = resolve(obj[pathKey]);
});
});
};
normalizePaths(['paths', 'webpack.aliases']);
module.exports = conf;