Skip to content

Commit 1bbd9e2

Browse files
committed
[TypeScript] Setup TypeScript type checking
1 parent 125dcb0 commit 1bbd9e2

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

packages/react-scripts/config/webpack.config.dev.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const path = require('path');
1313
const webpack = require('webpack');
1414
const HtmlWebpackPlugin = require('html-webpack-plugin');
1515
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
16+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
1617
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1718
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
1819
const eslintFormatter = require('react-dev-utils/eslintFormatter');
@@ -405,7 +406,13 @@ module.exports = {
405406
fileName: 'asset-manifest.json',
406407
publicPath: publicPath,
407408
}),
408-
],
409+
// TypeScript type checking
410+
paths.isTypeScript &&
411+
new ForkTsCheckerWebpackPlugin({
412+
async: false,
413+
watch: paths.appSrc,
414+
}),
415+
].filter(Boolean),
409416

410417
// Some libraries import Node modules but don't use them in the browser.
411418
// Tell Webpack to provide empty mocks for them so importing them works.

packages/react-scripts/config/webpack.config.prod.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const path = require('path');
1313
const webpack = require('webpack');
1414
const HtmlWebpackPlugin = require('html-webpack-plugin');
1515
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
16+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
1617
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
1718
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
1819
const ManifestPlugin = require('webpack-manifest-plugin');
@@ -477,7 +478,13 @@ module.exports = {
477478
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
478479
// You can remove this if you don't use Moment.js:
479480
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
480-
],
481+
// TypeScript type checking
482+
paths.isTypeScript &&
483+
new ForkTsCheckerWebpackPlugin({
484+
async: false,
485+
watch: paths.appSrc,
486+
}),
487+
].filter(Boolean),
481488
// Some libraries import Node modules but don't use them in the browser.
482489
// Tell Webpack to provide empty mocks for them so importing them works.
483490
node: {

packages/react-scripts/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,18 @@
4444
"eslint-plugin-jsx-a11y": "6.0.3",
4545
"eslint-plugin-react": "7.8.2",
4646
"file-loader": "1.1.11",
47+
"fork-ts-checker-webpack-plugin": "^0.4.6",
4748
"fs-extra": "5.0.0",
4849
"graphql": "0.13.2",
4950
"graphql-tag": "2.9.2",
5051
"html-webpack-plugin": "3.2.0",
5152
"identity-obj-proxy": "3.0.0",
52-
"loader-utils": "^1.1.0",
5353
"jest": "22.4.3",
54+
"loader-utils": "^1.1.0",
5455
"mini-css-extract-plugin": "^0.4.0",
5556
"object-assign": "4.1.1",
56-
"postcss-flexbugs-fixes": "3.3.1",
5757
"optimize-css-assets-webpack-plugin": "^4.0.1",
58+
"postcss-flexbugs-fixes": "3.3.1",
5859
"postcss-loader": "2.1.5",
5960
"promise": "8.0.1",
6061
"raf": "3.4.0",
@@ -65,6 +66,7 @@
6566
"svgr": "1.9.2",
6667
"sw-precache-webpack-plugin": "0.11.5",
6768
"thread-loader": "1.1.5",
69+
"typescript": "^3",
6870
"uglifyjs-webpack-plugin": "1.2.5",
6971
"url-loader": "1.0.1",
7072
"webpack": "4.8.3",

0 commit comments

Comments
 (0)