Skip to content

Commit bbce032

Browse files
committed
Use ts-checker-webpack-plugin for faster type checking
1 parent 7208666 commit bbce032

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const path = require('path');
1515
const webpack = require('webpack');
1616
const HtmlWebpackPlugin = require('html-webpack-plugin');
1717
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
18+
const TsCheckerWebpackPlugin = require('ts-checker-webpack-plugin');
1819
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1920
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
2021
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
@@ -143,14 +144,6 @@ module.exports = {
143144
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
144145
// { parser: { requireEnsure: false } },
145146

146-
// First, run the linter.
147-
// It's important to do this before Babel processes the JS.
148-
{
149-
test: /\.(ts|tsx)$/,
150-
loader: require.resolve('tslint-loader'),
151-
enforce: 'pre',
152-
include: paths.appSrc,
153-
},
154147
{
155148
test: /\.js$/,
156149
loader: require.resolve('source-map-loader'),
@@ -206,6 +199,9 @@ module.exports = {
206199
test: /\.(ts|tsx)$/,
207200
include: paths.appSrc,
208201
loader: require.resolve('ts-loader'),
202+
options: {
203+
transpileOnly: true,
204+
},
209205
},
210206
// "postcss" loader applies autoprefixer to our CSS.
211207
// "sass" loader compiles scss to css.
@@ -343,6 +339,12 @@ module.exports = {
343339
/module\.css\.d\.ts$/,
344340
/module\.scss\.d\.ts$/,
345341
]),
342+
// Type check the files
343+
new TsCheckerWebpackPlugin({
344+
tsconfig: path.join(paths.appPath, 'tsconfig.json'),
345+
tslint: path.join(paths.appPath, 'tslint.json'),
346+
memoryLimit: 2048,
347+
}),
346348
],
347349
// Some libraries import Node modules but don't use them in the browser.
348350
// Tell Webpack to provide empty mocks for them so importing them works.

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
1717
const ExtractTextPlugin = require('extract-text-webpack-plugin');
1818
const ManifestPlugin = require('webpack-manifest-plugin');
1919
const PostCssPipelineWebpackPlugin = require('postcss-pipeline-webpack-plugin');
20+
const TsCheckerWebpackPlugin = require('ts-checker-webpack-plugin');
2021
const cssnano = require('cssnano');
2122
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
2223
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
@@ -143,14 +144,6 @@ module.exports = {
143144
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
144145
// { parser: { requireEnsure: false } },
145146

146-
// First, run the linter.
147-
// It's important to do this before Typescript runs.
148-
{
149-
test: /\.(ts|tsx)$/,
150-
loader: require.resolve('tslint-loader'),
151-
enforce: 'pre',
152-
include: paths.appSrc,
153-
},
154147
{
155148
test: /\.js$/,
156149
loader: require.resolve('source-map-loader'),
@@ -198,6 +191,9 @@ module.exports = {
198191
test: /\.(ts|tsx)$/,
199192
include: paths.appSrc,
200193
loader: require.resolve('ts-loader'),
194+
options: {
195+
transpileOnly: true,
196+
},
201197
},
202198
// The notation here is somewhat confusing.
203199
// "postcss" loader applies autoprefixer to our CSS.
@@ -444,6 +440,12 @@ module.exports = {
444440
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
445441
// You can remove this if you don't use Moment.js:
446442
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
443+
// Type check the files
444+
new TsCheckerWebpackPlugin({
445+
tsconfig: path.join(paths.appPath, 'tsconfig.json'),
446+
tslint: path.join(paths.appPath, 'tslint.json'),
447+
memoryLimit: 2048,
448+
}),
447449
],
448450
// Some libraries import Node modules but don't use them in the browser.
449451
// Tell Webpack to provide empty mocks for them so importing them works.

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require('path');
44
const autoprefixer = require('autoprefixer');
55
const webpack = require('webpack');
66
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
7+
const TsCheckerWebpackPlugin = require('ts-checker-webpack-plugin');
78
const getClientEnvironment = require('./env');
89
const paths = require('./paths');
910

@@ -88,12 +89,6 @@ module.exports = function(storybookBaseConfig) {
8889

8990
// Register loaders
9091
storybookBaseConfig.module.rules = [
91-
{
92-
test: /\.(ts|tsx)$/,
93-
loader: require.resolve('tslint-loader'),
94-
enforce: 'pre',
95-
include: paths.appSrc,
96-
},
9792
{
9893
test: /\.js$/,
9994
loader: require.resolve('source-map-loader'),
@@ -149,6 +144,9 @@ module.exports = function(storybookBaseConfig) {
149144
test: /\.(ts|tsx)$/,
150145
include: paths.appSrc,
151146
loader: require.resolve('ts-loader'),
147+
options: {
148+
transpileOnly: true,
149+
},
152150
},
153151
// "postcss" loader applies autoprefixer to our CSS.
154152
// "sass" loader compiles scss to css.
@@ -266,6 +264,12 @@ module.exports = function(storybookBaseConfig) {
266264
/module\.css\.d\.ts$/,
267265
/module\.scss\.d\.ts$/,
268266
]),
267+
// Type check the files
268+
new TsCheckerWebpackPlugin({
269+
tsconfig: path.join(paths.appPath, 'tsconfig.json'),
270+
tslint: path.join(paths.appPath, 'tslint.json'),
271+
memoryLimit: 2048,
272+
}),
269273
]);
270274

271275
return storybookBaseConfig;

packages/react-scripts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"react-error-overlay": "^1.0.6",
4747
"sass-loader": "6.0.5",
4848
"style-loader": "0.17.0",
49+
"ts-checker-webpack-plugin": "^0.1.1",
4950
"ts-loader": "^2.0.3",
5051
"tslint": "^5.2.0",
5152
"tslint-loader": "^3.5.3",

0 commit comments

Comments
 (0)