Skip to content

Commit aa7247d

Browse files
committed
copy controlpanel over to controlpanel_with_summary
1 parent d9de473 commit aa7247d

File tree

19 files changed

+2401
-0
lines changed

19 files changed

+2401
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
build
11+
12+
# misc
13+
.DS_Store
14+
.env
15+
npm-debug.log

chapter-02/controlpanel_with_summary/README.md

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

0 commit comments

Comments
 (0)