Skip to content

Commit 00cc917

Browse files
authored
Merge pull request #45 from firstlookmedia/typescript-support
Typescript support
2 parents eb54291 + 54fd4b4 commit 00cc917

31 files changed

+6330
-4379
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jobs:
33
build:
44
working_directory: ~/react-scripts
55
docker:
6-
- image: circleci/node:6
6+
- image: circleci/node:12
77
steps:
88
- checkout
99
- restore_cache:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ template/schema.graphql
66
yarn-error.log
77
.watchmanconfig
88
.tern-port
9+
complete.queryMap.json

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "all",
3+
"singleQuote": true,
4+
"printWidth": 90
5+
}

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,11 @@ To install on OSX `brew bundle` in this directory.
5959

6060
## Persisted queries
6161

62-
By default, sites will not persist static queries. To enable persisted queries:
62+
To enable persisted queries:
6363

64-
1. add `PERSIST_QUERIES: "true"` to all build circle configs
65-
2. add `QUERIES_S3_BUCKET` property to all build and deploy circle configs and point it to the s3 bucket where the site's queries live
66-
3. upgrade to the newest version of React scripts that has the `get` and `post` fetcher methods
67-
4. install our forked version of relay compiler: https://github.com/firstlookmedia/relay contains the .tar.gz of the compiler and you refer to it like so in the `package.json`: https://github.com/firstlookmedia/relay/releases/download/v1.5.0-flm.1/relay-compiler-1.5.0-flm.1.tar.gz
64+
1. Add `PERSIST_QUERIES: "true"` in the build and runtime environments
65+
2. Point `QUERIES_S3_BUCKET` to an s3 bucket during build time to deploy queries, making them accessible to the graphql backend
66+
3. Upgrade to the newest version of React scripts that has the `GET` and `POST` fetcher methods
67+
4. Upgrade to relay >= 3.0
6868

6969
Note: persisted queries are always turned off during local development.
70-
71-
### relay compiler
72-
73-
We are using a forked version of relay similar to what the artsy folks are doing. Hopefully, this fork will get merged into relay proper, at which point we won't need to do anything special to get persisted static queries to work. Until then, we will need to stick to relay version `1.5.0` and if we do need to upgrade we'll have to update our fork, rebuild the compiler, and release it. The artsy folks and others have done an excellent job of keeping this fork up to date with subsequent relay releases, so this should not pose much a problem. In fact, it would be great for us to help with merging upstream relay releases into the PR version on the relay repository if necessary.
74-

bin/react-scripts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const args = process.argv.slice(3);
1111

1212
switch (script) {
1313
case 'build':
14+
case 'build-queries':
1415
case 'start':
1516
case 'upload':
1617
case 'upload-queries':

config/babelOptions.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const packageConfig = require('./packageConfig');
2+
3+
const useReactHotLoader = typeof packageConfig.useReactHotLoader !== 'undefined'
4+
? packageConfig.useReactHotLoader
5+
: true;
6+
7+
const babelOptions = {
8+
passPerPreset: true,
9+
presets: [
10+
[
11+
'@babel/preset-env',
12+
{
13+
useBuiltIns: 'entry',
14+
corejs: 3,
15+
},
16+
],
17+
'@babel/typescript',
18+
'@babel/react',
19+
],
20+
plugins: [
21+
[
22+
'@babel/transform-runtime',
23+
{
24+
corejs: 3,
25+
},
26+
],
27+
'@loadable/babel-plugin',
28+
useReactHotLoader && 'react-hot-loader/babel',
29+
[
30+
'relay',
31+
{
32+
compat: packageConfig.relayCompatMode || false,
33+
artifactDirectory: 'src/__generated__',
34+
schema: 'schema.graphql',
35+
},
36+
],
37+
'@babel/plugin-syntax-dynamic-import',
38+
'@babel/plugin-syntax-import-meta',
39+
'@babel/plugin-proposal-class-properties',
40+
'@babel/plugin-proposal-json-strings',
41+
'@babel/plugin-proposal-function-sent',
42+
'@babel/plugin-proposal-export-namespace-from',
43+
'@babel/plugin-proposal-numeric-separator',
44+
'@babel/plugin-proposal-throw-expressions',
45+
'@babel/plugin-proposal-optional-chaining',
46+
'@babel/plugin-proposal-nullish-coalescing-operator',
47+
'@babel/plugin-proposal-object-rest-spread',
48+
'@babel/plugin-transform-for-of',
49+
].filter(Boolean),
50+
};
51+
52+
module.exports = babelOptions;

config/packageConfig.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const path = require('path');
2+
3+
const packageConfig = require(path.resolve('package.json'));
4+
5+
const reactScriptPackageConfig = {
6+
...packageConfig['react-scripts'],
7+
};
8+
9+
module.exports = reactScriptPackageConfig;

config/webpack.client.dev.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
const webpack = require('webpack');
22
const merge = require('webpack-merge');
3+
const path = require('path');
4+
const LoadablePlugin = require('@loadable/webpack-plugin');
35
const defaults = require('./webpack.defaults');
46

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-
}],
7+
const config = merge.smart(
8+
{
9+
module: {
10+
rules: [
11+
{
12+
test: /\.css$/,
13+
include: path.resolve('src'),
14+
use: ['style-loader'],
15+
},
16+
{
17+
test: /\.css$/,
18+
include: path.resolve('node_modules'),
19+
use: ['style-loader'],
20+
},
21+
{
22+
test: /\.scss$/,
23+
use: ['style-loader'],
24+
},
25+
],
26+
},
1427
},
15-
}, defaults, {
16-
devtool: 'eval-source-map',
17-
entry: ['webpack-hot-middleware/client'],
18-
plugins: [new webpack.HotModuleReplacementPlugin()],
19-
});
28+
defaults,
29+
{
30+
devtool: 'eval-source-map',
31+
entry: ['webpack-hot-middleware/client'],
32+
plugins: [
33+
new LoadablePlugin({ filename: 'stats.json', writeToDisk: true }),
34+
new webpack.HotModuleReplacementPlugin(),
35+
],
36+
},
37+
);
2038

2139
module.exports = config;

config/webpack.client.prod.js

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,72 @@ const ProgressBarPlugin = require('progress-bar-webpack-plugin');
44
const merge = require('webpack-merge');
55
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
66
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
7+
const path = require('path');
8+
const LoadablePlugin = require('@loadable/webpack-plugin');
79
const defaults = require('./webpack.defaults');
10+
const babelOptions = require('./babelOptions');
811

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-
}],
12+
const config = merge.smart(
13+
{
14+
module: {
15+
rules: [
16+
{
17+
test: /\.css$/,
18+
include: path.resolve('src'),
19+
use: [MiniCSSExtractPlugin.loader],
20+
},
21+
{
22+
test: /\.css$/,
23+
include: path.resolve('node_modules'),
24+
use: [MiniCSSExtractPlugin.loader],
25+
},
26+
{
27+
test: /\.scss$/,
28+
use: [MiniCSSExtractPlugin.loader],
29+
},
30+
{
31+
test: /\.tsx*$/,
32+
include: [path.resolve('src')],
33+
use: [
34+
{
35+
loader: 'babel-loader',
36+
options: babelOptions,
37+
},
38+
{
39+
loader: 'ts-loader',
40+
},
41+
],
42+
},
43+
],
44+
},
1845
},
19-
}, defaults, {
20-
mode: 'production',
21-
output: {
22-
filename: '[hash].js',
46+
defaults,
47+
{
48+
mode: 'production',
49+
output: {
50+
filename: '[hash].js',
51+
},
52+
plugins: [
53+
new LoadablePlugin({ filename: 'stats.json', writeToDisk: true }),
54+
new ManifestPlugin({ fileName: 'manifest.json' }),
55+
new ManifestPlugin({ fileName: `manifest.${Date.now()}.json` }),
56+
new webpack.DefinePlugin({
57+
'process.env.NODE_ENV': '"production"',
58+
}),
59+
new ProgressBarPlugin(),
60+
new MiniCSSExtractPlugin({
61+
filename: '[contenthash].css',
62+
}),
63+
new OptimizeCSSAssetsPlugin({
64+
cssProcessorOptions: {
65+
map: {
66+
inline: false,
67+
},
68+
reduceIdents: false,
69+
},
70+
}),
71+
],
2372
},
24-
plugins: [
25-
new ManifestPlugin({ fileName: 'manifest.json' }),
26-
new ManifestPlugin({ fileName: `manifest.${Date.now()}.json` }),
27-
new webpack.DefinePlugin({
28-
'process.env.NODE_ENV': '"production"',
29-
}),
30-
new ProgressBarPlugin(),
31-
new MiniCSSExtractPlugin({
32-
filename: '[contenthash].css',
33-
}),
34-
new OptimizeCSSAssetsPlugin({}),
35-
],
36-
});
73+
);
3774

3875
module.exports = config;

0 commit comments

Comments
 (0)