Skip to content

Commit 2c2f2ea

Browse files
authored
Merge branch 'next' into master
2 parents c8da77c + 1b54d97 commit 2c2f2ea

28 files changed

+5398
-2710
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
node_modules
22
template/yarn.lock
33
template/package.json
4+
template/schema.json
5+
template/schema.graphql
6+
yarn-error.log
7+
.watchmanconfig
8+
.tern-port

README.md

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
# react-scripts
22

3-
This provides configuration for FLM's isomorphic React apps.
3+
Provides configuration for universal React/Relay apps.
44

5-
## Install
5+
By default we expect a graphql server to exist as a separate service.
6+
The default template will query for `{ viewer { id } }` but this is not
7+
required of the schema.
68

7-
tl;dr
9+
## Install
810

911
``` bash
1012
npm install -g create-react-app
1113

1214
create-react-app --scripts-version=git+ssh://git@github.com/firstlookmedia/react-scripts.git my-app
1315
cd my-app
14-
npm start
16+
yarn update-schema
17+
yarn start
1518
```
1619

1720
## Usage
1821

1922
`react-scripts` expects at least the following files:
2023

2124
```
22-
src/index.js # entry to the client-side app
23-
server.js # entry to the server
25+
src/index.js # entry to the client-side app
26+
server.js # entry to the server
27+
schema.graphql # your graphql schema
2428
```
2529

2630
The output will become:
@@ -34,45 +38,21 @@ build/assets/2d0823jd.css # any other compiled assets (css, images, fonts)
3438

3539
---
3640

37-
#### `npm start`
41+
#### `yarn start`
3842

3943
Starts the development environment:
4044

4145
- The app server, which auto-reloads on [http://localhost:3232](http://localhost:3232)
4246
- A webpack dev server, which hot-reloads and proxies requests to the app server,
4347
on [http://localhost:3233](http://localhost:3233)
4448

45-
#### `npm build`
49+
#### `yarn build`
4650

4751
Builds the production assets to the `build` folder.
4852

49-
#### `npm test`
50-
51-
You will need `watchman` to use `npm test` without `CI=true`. To install on OSX `brew bundle` in this directory.
52-
53-
Runs mocha tests. `react-scripts` will look for any file named `__spec.js`.
53+
#### `yarn test`
5454

55-
`react-scripts` adds chai assertion helpers for
56-
[enzyme](https://github.com/producthunt/chai-enzyme)
57-
and [sinon](https://github.com/domenic/sinon-chai)
55+
Runs jest tests. `react-scripts` will look for any file named `__spec.js`.
5856

59-
Example test:
60-
61-
``` javascript
62-
import React from 'react';
63-
import { mount } from 'enzyme';
64-
import { expect } from 'chai';
65-
66-
import Wrapper from '.';
67-
68-
describe('Wrapper', () => {
69-
it('renders supplied children', () => {
70-
const wrapper = mount(
71-
<Wrapper>
72-
<div>child</div>
73-
</Wrapper>
74-
);
75-
expect(wrapper).to.contain(<div>child</div>);
76-
});
77-
});
78-
```
57+
You will need `watchman` to use `yarn test` without `CI=true`.
58+
To install on OSX `brew bundle` in this directory.

config/webpack.client.dev.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
const webpack = require('webpack');
2+
const merge = require('webpack-merge');
23
const defaults = require('./webpack.defaults');
34

4-
const config = Object.assign({}, defaults, {
5-
devtool: 'source',
6-
module: Object.assign({}, defaults.module, {
7-
loaders: defaults.module.loaders.map(loader => {
8-
if (loader.name === 'css') {
9-
return Object.assign({}, loader, {
10-
loader: `style-loader!${loader.loader}`,
11-
});
12-
}
13-
return loader;
14-
}),
15-
}),
16-
entry: [
17-
require.resolve('webpack-hot-middleware/client'),
18-
].concat(defaults.entry),
19-
plugins: defaults.plugins.concat([
20-
new webpack.HotModuleReplacementPlugin(),
21-
]),
22-
debug: true,
5+
const config = merge.smart({
6+
module: {
7+
rules: [{
8+
test: /\.css$/,
9+
use: ['style-loader'],
10+
}, {
11+
test: /\.scss$/,
12+
use: ['style-loader'],
13+
}],
14+
},
15+
}, defaults, {
16+
devtool: 'eval-source-map',
17+
entry: ['webpack-hot-middleware/client'],
18+
plugins: [new webpack.HotModuleReplacementPlugin()],
2319
});
2420

2521
module.exports = config;

config/webpack.client.prod.js

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
11
const webpack = require('webpack');
2-
const ExtractTextPlugin = require('extract-text-webpack-plugin');
32
const ManifestPlugin = require('webpack-manifest-plugin');
43
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
5-
4+
const merge = require('webpack-merge');
5+
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
6+
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
67
const defaults = require('./webpack.defaults');
78

8-
const config = Object.assign({}, defaults, {
9-
output: Object.assign({}, defaults.output, {
9+
const config = merge.smart({
10+
module: {
11+
rules: [{
12+
test: /\.css$/,
13+
use: [MiniCSSExtractPlugin.loader],
14+
}, {
15+
test: /\.scss$/,
16+
use: [MiniCSSExtractPlugin.loader],
17+
}],
18+
},
19+
}, defaults, {
20+
mode: 'production',
21+
output: {
1022
filename: '[hash].js',
11-
}),
12-
module: Object.assign({}, defaults.module, {
13-
loaders: defaults.module.loaders.map(loader => {
14-
if (loader.name === 'css') {
15-
return Object.assign({}, loader, {
16-
loader: ExtractTextPlugin.extract(
17-
'style-loader',
18-
loader.loader,
19-
{ allChunks: true }
20-
),
21-
});
22-
}
23-
return loader;
24-
}),
25-
}),
26-
plugins: defaults.plugins.concat([
23+
},
24+
plugins: [
2725
new ManifestPlugin({ fileName: 'manifest.json' }),
2826
new ManifestPlugin({ fileName: `manifest.${Date.now()}.json` }),
29-
new ExtractTextPlugin('[contenthash].css'),
3027
new webpack.DefinePlugin({
3128
'process.env.NODE_ENV': '"production"',
3229
}),
33-
new webpack.optimize.OccurenceOrderPlugin(),
34-
new webpack.optimize.DedupePlugin(),
35-
new webpack.optimize.UglifyJsPlugin({
36-
compressor: {
37-
warnings: false,
38-
},
39-
mangle: true,
40-
}),
4130
new ProgressBarPlugin(),
42-
]),
31+
new MiniCSSExtractPlugin({
32+
filename: '[contenthash].css',
33+
}),
34+
new OptimizeCSSAssetsPlugin({}),
35+
],
4336
});
4437

4538
module.exports = config;

config/webpack.defaults.js

Lines changed: 100 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
const path = require('path');
2-
const precss = require('precss');
32
const autoprefixer = require('autoprefixer');
3+
const precss = require('precss');
44
const postcssCalc = require('postcss-calc');
55

6+
const cssOptions = {
7+
sourceMap: true,
8+
modules: true,
9+
importLoaders: 1,
10+
context: 'src/components',
11+
localIdentName: '[path][local]',
12+
};
13+
614
module.exports = {
15+
mode: 'development',
16+
context: __dirname,
717
entry: [
8-
require.resolve('babel-polyfill'),
18+
'babel-polyfill',
919
path.resolve('src/index.js'),
1020
],
1121
output: {
@@ -15,51 +25,106 @@ module.exports = {
1525
},
1626
plugins: [],
1727
resolve: {
18-
extensions: ['', '.js', '.json'],
19-
},
20-
resolveLoader: {
21-
root: path.resolve(__dirname, '../node_modules'),
28+
modules: ['node_modules'],
2229
},
2330
module: {
24-
loaders: [{
31+
rules: [{
2532
test: /\.js$/,
26-
loader: 'babel-loader',
2733
include: [path.resolve('src'), path.resolve('server.js')],
28-
query: {
29-
passPerPreset: true,
30-
presets: [
31-
'babel-preset-react',
32-
'babel-preset-es2015',
33-
'babel-preset-stage-0',
34-
].map(require.resolve),
35-
plugins: [
36-
'babel-plugin-transform-runtime',
37-
].map(require.resolve),
38-
},
34+
use: [{
35+
loader: 'babel-loader',
36+
options: {
37+
passPerPreset: true,
38+
presets: [
39+
'babel-preset-react',
40+
'babel-preset-env',
41+
'babel-preset-stage-0',
42+
],
43+
plugins: [
44+
'babel-plugin-transform-runtime',
45+
'react-hot-loader/babel',
46+
],
47+
},
48+
}],
3949
}, {
40-
name: 'css',
4150
test: /\.css$/,
42-
loader: 'css?modules&importLoaders=1&context=src/components&localIdentName=[path][local]&-autoprefixer!postcss',
51+
use: [
52+
{
53+
loader: 'css-loader',
54+
options: cssOptions,
55+
},
56+
{
57+
loader: 'postcss-loader',
58+
options: {
59+
sourceMap: true,
60+
ident: 'postcss',
61+
plugins: [
62+
autoprefixer(),
63+
postcssCalc(),
64+
precss(),
65+
],
66+
},
67+
},
68+
],
4369
}, {
44-
test: /\.(jpe?g|png|gif|svg)$/i,
45-
loaders: [
46-
'file?hash=sha512&digest=hex&name=[hash].[ext]',
47-
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false',
70+
test: /\.scss$/,
71+
use: [
72+
{
73+
loader: 'css-loader',
74+
options: { ...cssOptions, importLoaders: 3 },
75+
},
76+
'resolve-url-loader',
77+
{
78+
loader: 'postcss-loader',
79+
options: {
80+
sourceMap: true,
81+
82+
// needed to have two different postcss configs
83+
// without this, it just silently fails
84+
ident: 'postcss-sass',
85+
86+
plugins: [
87+
autoprefixer(),
88+
],
89+
},
90+
},
91+
{
92+
loader: 'sass-loader',
93+
options: {
94+
sourceMap: true,
95+
},
96+
},
4897
],
4998
}, {
50-
test: /\.woff2?(\?v=\d+\.\d+\.\d+)?$/,
51-
loader: 'url?limit=10000&mimetype=application/font-woff',
99+
test: /\.(jpe?g|png|gif|svg)$/i,
100+
use: [
101+
{
102+
loader: 'file-loader',
103+
options: {
104+
hash: 'sha512',
105+
digest: 'hex',
106+
name: '[hash].[ext]',
107+
},
108+
},
109+
{
110+
loader: 'image-webpack-loader',
111+
options: {
112+
bypassOnDebug: true,
113+
},
114+
},
115+
],
52116
}, {
53-
test: /\.json$/,
54-
loader: 'json',
117+
test: /\.woff2?$/,
118+
use: [{
119+
loader: 'url-loader',
120+
options: {
121+
limit: 10000,
122+
mimetype: 'application/font-woff',
123+
},
124+
}],
55125
}, {
56126
test: /masonry|imagesloaded|fizzy\-ui\-utils|desandro\-|outlayer|get\-size|doc\-ready|eventie|eventemitter/,
57-
loader: 'imports?define=>false&this=>window',
127+
use: 'imports-loader?define=>false&this=>window',
58128
}],
59129
},
60-
postcss: () => [
61-
precss,
62-
autoprefixer,
63-
postcssCalc,
64-
],
65130
};

config/webpack.server.dev.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
const defaults = require('./webpack.server');
22

3-
module.exports = Object.assign({}, defaults, {
4-
debug: true,
5-
});
3+
module.exports = Object.assign({}, defaults, {});

0 commit comments

Comments
 (0)