Skip to content

Commit eb4460c

Browse files
author
Jasdeep
committed
After running npm run eject to expose dependencies & config files
1 parent b870f10 commit eb4460c

12 files changed

+1454
-57
lines changed

config/env.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
2+
// injected into the application via DefinePlugin in Webpack configuration.
3+
4+
var REACT_APP = /^REACT_APP_/i;
5+
6+
function getClientEnvironment(publicUrl) {
7+
var raw = Object
8+
.keys(process.env)
9+
.filter(key => REACT_APP.test(key))
10+
.reduce((env, key) => {
11+
env[key] = process.env[key];
12+
return env;
13+
}, {
14+
// Useful for determining whether we’re running in production mode.
15+
// Most importantly, it switches React into the correct mode.
16+
'NODE_ENV': process.env.NODE_ENV || 'development',
17+
// Useful for resolving the correct path to static assets in `public`.
18+
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
19+
// This should only be used as an escape hatch. Normally you would put
20+
// images into the `src` and `import` them in code to get their paths.
21+
'PUBLIC_URL': publicUrl
22+
});
23+
// Stringify all values so we can feed into Webpack DefinePlugin
24+
var stringified = {
25+
'process.env': Object
26+
.keys(raw)
27+
.reduce((env, key) => {
28+
env[key] = JSON.stringify(raw[key]);
29+
return env;
30+
}, {})
31+
};
32+
33+
return { raw, stringified };
34+
}
35+
36+
module.exports = getClientEnvironment;

config/jest/cssTransform.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This is a custom Jest transformer turning style imports into empty objects.
2+
// http://facebook.github.io/jest/docs/tutorial-webpack.html
3+
4+
module.exports = {
5+
process() {
6+
return 'module.exports = {};';
7+
},
8+
getCacheKey(fileData, filename) {
9+
// The output is always the same.
10+
return 'cssTransform';
11+
},
12+
};

config/jest/fileTransform.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const path = require('path');
2+
3+
// This is a custom Jest transformer turning file imports into filenames.
4+
// http://facebook.github.io/jest/docs/tutorial-webpack.html
5+
6+
module.exports = {
7+
process(src, filename) {
8+
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
9+
},
10+
};

config/paths.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
var path = require('path');
2+
var fs = require('fs');
3+
var url = require('url');
4+
5+
// Make sure any symlinks in the project folder are resolved:
6+
// https://github.com/facebookincubator/create-react-app/issues/637
7+
var appDirectory = fs.realpathSync(process.cwd());
8+
function resolveApp(relativePath) {
9+
return path.resolve(appDirectory, relativePath);
10+
}
11+
12+
// We support resolving modules according to `NODE_PATH`.
13+
// This lets you use absolute paths in imports inside large monorepos:
14+
// https://github.com/facebookincubator/create-react-app/issues/253.
15+
16+
// It works similar to `NODE_PATH` in Node itself:
17+
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
18+
19+
// We will export `nodePaths` as an array of absolute paths.
20+
// It will then be used by Webpack configs.
21+
// Jest doesn’t need this because it already handles `NODE_PATH` out of the box.
22+
23+
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
24+
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
25+
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
26+
27+
var nodePaths = (process.env.NODE_PATH || '')
28+
.split(process.platform === 'win32' ? ';' : ':')
29+
.filter(Boolean)
30+
.filter(folder => !path.isAbsolute(folder))
31+
.map(resolveApp);
32+
33+
var envPublicUrl = process.env.PUBLIC_URL;
34+
35+
function ensureSlash(path, needsSlash) {
36+
var hasSlash = path.endsWith('/');
37+
if (hasSlash && !needsSlash) {
38+
return path.substr(path, path.length - 1);
39+
} else if (!hasSlash && needsSlash) {
40+
return path + '/';
41+
} else {
42+
return path;
43+
}
44+
}
45+
46+
function getPublicUrl(appPackageJson) {
47+
return envPublicUrl || require(appPackageJson).homepage;
48+
}
49+
50+
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
51+
// "public path" at which the app is served.
52+
// Webpack needs to know it to put the right <script> hrefs into HTML even in
53+
// single-page apps that may serve index.html for nested URLs like /todos/42.
54+
// We can't use a relative path in HTML because we don't want to load something
55+
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
56+
function getServedPath(appPackageJson) {
57+
var publicUrl = getPublicUrl(appPackageJson);
58+
var servedUrl = envPublicUrl || (
59+
publicUrl ? url.parse(publicUrl).pathname : '/'
60+
);
61+
return ensureSlash(servedUrl, true);
62+
}
63+
64+
// config after eject: we're in ./config/
65+
module.exports = {
66+
appBuild: resolveApp('build'),
67+
appPublic: resolveApp('public'),
68+
appHtml: resolveApp('public/index.html'),
69+
appIndexJs: resolveApp('src/index.js'),
70+
appPackageJson: resolveApp('package.json'),
71+
appSrc: resolveApp('src'),
72+
yarnLockFile: resolveApp('yarn.lock'),
73+
testsSetup: resolveApp('src/setupTests.js'),
74+
appNodeModules: resolveApp('node_modules'),
75+
ownNodeModules: resolveApp('node_modules'),
76+
nodePaths: nodePaths,
77+
publicUrl: getPublicUrl(resolveApp('package.json')),
78+
servedPath: getServedPath(resolveApp('package.json'))
79+
};

config/polyfills.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if (typeof Promise === 'undefined') {
2+
// Rejection tracking prevents a common issue where React gets into an
3+
// inconsistent state due to an error, but it gets swallowed by a Promise,
4+
// and the user has no idea what causes React's erratic future behavior.
5+
require('promise/lib/rejection-tracking').enable();
6+
window.Promise = require('promise/lib/es6-extensions.js');
7+
}
8+
9+
// fetch() polyfill for making API calls.
10+
require('whatwg-fetch');
11+
12+
// Object.assign() is commonly used with React.
13+
// It will use the native implementation if it's present and isn't buggy.
14+
Object.assign = require('object-assign');

config/webpack.config.dev.js

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
var autoprefixer = require('autoprefixer');
2+
var webpack = require('webpack');
3+
var HtmlWebpackPlugin = require('html-webpack-plugin');
4+
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
5+
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
6+
var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
7+
var getClientEnvironment = require('./env');
8+
var paths = require('./paths');
9+
10+
11+
12+
// Webpack uses `publicPath` to determine where the app is being served from.
13+
// In development, we always serve from the root. This makes config easier.
14+
var publicPath = '/';
15+
// `publicUrl` is just like `publicPath`, but we will provide it to our app
16+
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
17+
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
18+
var publicUrl = '';
19+
// Get environment variables to inject into our app.
20+
var env = getClientEnvironment(publicUrl);
21+
22+
// This is the development configuration.
23+
// It is focused on developer experience and fast rebuilds.
24+
// The production configuration is different and lives in a separate file.
25+
module.exports = {
26+
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
27+
// See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
28+
devtool: 'cheap-module-source-map',
29+
// These are the "entry points" to our application.
30+
// This means they will be the "root" imports that are included in JS bundle.
31+
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
32+
entry: [
33+
// Include an alternative client for WebpackDevServer. A client's job is to
34+
// connect to WebpackDevServer by a socket and get notified about changes.
35+
// When you save a file, the client will either apply hot updates (in case
36+
// of CSS changes), or refresh the page (in case of JS changes). When you
37+
// make a syntax error, this client will display a syntax error overlay.
38+
// Note: instead of the default WebpackDevServer client, we use a custom one
39+
// to bring better experience for Create React App users. You can replace
40+
// the line below with these two lines if you prefer the stock client:
41+
// require.resolve('webpack-dev-server/client') + '?/',
42+
// require.resolve('webpack/hot/dev-server'),
43+
require.resolve('react-dev-utils/webpackHotDevClient'),
44+
// We ship a few polyfills by default:
45+
require.resolve('./polyfills'),
46+
// Finally, this is your app's code:
47+
paths.appIndexJs
48+
// We include the app code last so that if there is a runtime error during
49+
// initialization, it doesn't blow up the WebpackDevServer client, and
50+
// changing JS code would still trigger a refresh.
51+
],
52+
output: {
53+
// Next line is not used in dev but WebpackDevServer crashes without it:
54+
path: paths.appBuild,
55+
// Add /* filename */ comments to generated require()s in the output.
56+
pathinfo: true,
57+
// This does not produce a real file. It's just the virtual path that is
58+
// served by WebpackDevServer in development. This is the JS bundle
59+
// containing code from all our entry points, and the Webpack runtime.
60+
filename: 'static/js/bundle.js',
61+
// This is the URL that app is served from. We use "/" in development.
62+
publicPath: publicPath
63+
},
64+
resolve: {
65+
// This allows you to set a fallback for where Webpack should look for modules.
66+
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
67+
// We use `fallback` instead of `root` because we want `node_modules` to "win"
68+
// if there any conflicts. This matches Node resolution mechanism.
69+
// https://github.com/facebookincubator/create-react-app/issues/253
70+
fallback: paths.nodePaths,
71+
// These are the reasonable defaults supported by the Node ecosystem.
72+
// We also include JSX as a common component filename extension to support
73+
// some tools, although we do not recommend using it, see:
74+
// https://github.com/facebookincubator/create-react-app/issues/290
75+
extensions: ['.js', '.json', '.jsx', ''],
76+
alias: {
77+
// Support React Native Web
78+
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
79+
'react-native': 'react-native-web'
80+
}
81+
},
82+
83+
module: {
84+
// First, run the linter.
85+
// It's important to do this before Babel processes the JS.
86+
preLoaders: [
87+
{
88+
test: /\.(js|jsx)$/,
89+
loader: 'eslint',
90+
include: paths.appSrc,
91+
}
92+
],
93+
loaders: [
94+
// ** ADDING/UPDATING LOADERS **
95+
// The "url" loader handles all assets unless explicitly excluded.
96+
// The `exclude` list *must* be updated with every change to loader extensions.
97+
// When adding a new loader, you must add its `test`
98+
// as a new entry in the `exclude` list for "url" loader.
99+
100+
// "url" loader embeds assets smaller than specified size as data URLs to avoid requests.
101+
// Otherwise, it acts like the "file" loader.
102+
{
103+
exclude: [
104+
/\.html$/,
105+
/\.(js|jsx)$/,
106+
/\.css$/,
107+
/\.json$/,
108+
/\.svg$/
109+
],
110+
loader: 'url',
111+
query: {
112+
limit: 10000,
113+
name: 'static/media/[name].[hash:8].[ext]'
114+
}
115+
},
116+
// Process JS with Babel.
117+
{
118+
test: /\.(js|jsx)$/,
119+
include: paths.appSrc,
120+
loader: 'babel',
121+
query: {
122+
123+
// This is a feature of `babel-loader` for webpack (not Babel itself).
124+
// It enables caching results in ./node_modules/.cache/babel-loader/
125+
// directory for faster rebuilds.
126+
cacheDirectory: true
127+
}
128+
},
129+
// "postcss" loader applies autoprefixer to our CSS.
130+
// "css" loader resolves paths in CSS and adds assets as dependencies.
131+
// "style" loader turns CSS into JS modules that inject <style> tags.
132+
// In production, we use a plugin to extract that CSS to a file, but
133+
// in development "style" loader enables hot editing of CSS.
134+
{
135+
test: /\.css$/,
136+
loader: 'style!css?importLoaders=1!postcss'
137+
},
138+
// JSON is not enabled by default in Webpack but both Node and Browserify
139+
// allow it implicitly so we also enable it.
140+
{
141+
test: /\.json$/,
142+
loader: 'json'
143+
},
144+
// "file" loader for svg
145+
{
146+
test: /\.svg$/,
147+
loader: 'file',
148+
query: {
149+
name: 'static/media/[name].[hash:8].[ext]'
150+
}
151+
}
152+
// ** STOP ** Are you adding a new loader?
153+
// Remember to add the new extension(s) to the "url" loader exclusion list.
154+
]
155+
},
156+
157+
// We use PostCSS for autoprefixing only.
158+
postcss: function() {
159+
return [
160+
autoprefixer({
161+
browsers: [
162+
'>1%',
163+
'last 4 versions',
164+
'Firefox ESR',
165+
'not ie < 9', // React doesn't support IE8 anyway
166+
]
167+
}),
168+
];
169+
},
170+
plugins: [
171+
// Makes some environment variables available in index.html.
172+
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
173+
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
174+
// In development, this will be an empty string.
175+
new InterpolateHtmlPlugin(env.raw),
176+
// Generates an `index.html` file with the <script> injected.
177+
new HtmlWebpackPlugin({
178+
inject: true,
179+
template: paths.appHtml,
180+
}),
181+
// Makes some environment variables available to the JS code, for example:
182+
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
183+
new webpack.DefinePlugin(env.stringified),
184+
// This is necessary to emit hot updates (currently CSS only):
185+
new webpack.HotModuleReplacementPlugin(),
186+
// Watcher doesn't work well if you mistype casing in a path so we use
187+
// a plugin that prints an error when you attempt to do this.
188+
// See https://github.com/facebookincubator/create-react-app/issues/240
189+
new CaseSensitivePathsPlugin(),
190+
// If you require a missing module and then `npm install` it, you still have
191+
// to restart the development server for Webpack to discover it. This plugin
192+
// makes the discovery automatic so you don't have to restart.
193+
// See https://github.com/facebookincubator/create-react-app/issues/186
194+
new WatchMissingNodeModulesPlugin(paths.appNodeModules)
195+
],
196+
// Some libraries import Node modules but don't use them in the browser.
197+
// Tell Webpack to provide empty mocks for them so importing them works.
198+
node: {
199+
fs: 'empty',
200+
net: 'empty',
201+
tls: 'empty'
202+
}
203+
};

0 commit comments

Comments
 (0)