Skip to content

Commit 2433ae6

Browse files
committed
eject & add basic babel-relay-plugin stuff
since create-react-app does not yet support the babel relay plugin we need to eject !!! ... although this might be coming to a repo near you soon facebook/create-react-app#462 but for now we have to eject, install babel-relay-plugin, babel-plugin-react-relay, and "babel-preset-stage-0 (for some reason) manually ... then for some other reason I cannot get the babelrc to run from the package.json so I needed to add the .babelrc file and override that so now .babelrc should call babelRelayPlugin so we can compile the queries etc in the transpile ... note this needs the schema so you need to update the schema.json and schema.graphql files using the getSchema.js util (maybe I should move all these into config? .. I kinda want to keep the eject clean though) btw the webkit-dev-server will only reload the schema if npm is restarted so if you want to change the schema on the server side you need to restart npm and call node ./getSchema.js in between to update relay also while I was ejecting I did some small tweaks to their scripts that shit me to tears ... like clearing the screen on each build (I like console output dam it) and starting the browser all the time
1 parent 38cb56c commit 2433ae6

14 files changed

+1107
-5
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"passPerPreset": true,
3+
"plugins": ["./babelRelayPlugin"],
4+
"presets": [
5+
"react",
6+
"es2015",
7+
"stage-0",
8+
]
9+
}

babelRelayPlugin.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// show a little message when we update our schema for the babel-relay
2+
console.log("giving babel-relay-plugin the current schema");
3+
4+
// `babel-relay-plugin` returns a function for creating plugin instances
5+
var getBabelRelayPlugin = require('babel-relay-plugin');
6+
7+
// get schema data
8+
var schema = require(__dirname + '/schema.json');
9+
10+
// create a plugin instance
11+
module.exports = getBabelRelayPlugin(schema.data);
12+

config/env.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
return Object
8+
.keys(process.env)
9+
.filter(key => REACT_APP.test(key))
10+
.reduce((env, key) => {
11+
env['process.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+
'process.env.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+
'process.env.PUBLIC_URL': JSON.stringify(publicUrl)
24+
});
25+
}
26+
27+
module.exports = getClientEnvironment;

config/jest/CSSStub.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

config/jest/FileStub.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "test-file-stub";

config/paths.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
testsSetup: resolveApp('src/setupTests.js'),
36+
appNodeModules: resolveApp('node_modules'),
37+
ownNodeModules: resolveApp('node_modules'),
38+
nodePaths: nodePaths
39+
};

config/polyfills.js

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');

config/webpack.config.dev.js

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

0 commit comments

Comments
 (0)