Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Commit 99a55a9

Browse files
committed
Add support for fork-ts-checker-webpack-plugin
1 parent 606b651 commit 99a55a9

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

packages/react-scripts/config/paths.js

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ if (
114114
testsSetup: resolveOwn('template/src/setupTests.ts'),
115115
appNodeModules: resolveOwn('node_modules'),
116116
appTsConfig: resolveOwn('template/tsconfig.json'),
117+
appTsLint: resolveOwn('template/tslint.json'),
117118
appTsTestConfig: resolveOwn('template/tsconfig.test.json'),
118119
publicUrl: getPublicUrl(resolveOwn('package.json')),
119120
servedPath: getServedPath(resolveOwn('package.json')),

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

+17-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1818
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1919
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
2020
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
21+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
2122
const getClientEnvironment = require('./env');
2223
const paths = require('./paths');
2324

@@ -134,14 +135,6 @@ module.exports = {
134135
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
135136
// { parser: { requireEnsure: false } },
136137

137-
// First, run the linter.
138-
// It's important to do this before Babel processes the JS.
139-
{
140-
test: /\.(ts|tsx)$/,
141-
loader: require.resolve('tslint-loader'),
142-
enforce: 'pre',
143-
include: paths.appSrc,
144-
},
145138
{
146139
test: /\.js$/,
147140
loader: require.resolve('source-map-loader'),
@@ -168,7 +161,15 @@ module.exports = {
168161
{
169162
test: /\.(ts|tsx)$/,
170163
include: paths.appSrc,
171-
loader: require.resolve('ts-loader'),
164+
use: [
165+
{
166+
loader: require.resolve('ts-loader'),
167+
options: {
168+
// disable type checker - we will use it in fork plugin
169+
transpileOnly: true,
170+
},
171+
},
172+
],
172173
},
173174
// "postcss" loader applies autoprefixer to our CSS.
174175
// "css" loader resolves paths in CSS and adds assets as dependencies.
@@ -262,6 +263,13 @@ module.exports = {
262263
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
263264
// You can remove this if you don't use Moment.js:
264265
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
266+
// Perform type checking and linting in a separate process to speed up compilation
267+
new ForkTsCheckerWebpackPlugin({
268+
async: false,
269+
watch: paths.appSrc,
270+
tsconfig: paths.appTsConfig,
271+
tslint: paths.appTsLint,
272+
}),
265273
],
266274
// Some libraries import Node modules but don't use them in the browser.
267275
// Tell Webpack to provide empty mocks for them so importing them works.

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

+17-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const ManifestPlugin = require('webpack-manifest-plugin');
1919
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
2020
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
2121
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
22+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
2223
const paths = require('./paths');
2324
const getClientEnvironment = require('./env');
2425

@@ -138,14 +139,6 @@ module.exports = {
138139
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
139140
// { parser: { requireEnsure: false } },
140141

141-
// First, run the linter.
142-
// It's important to do this before Typescript runs.
143-
{
144-
test: /\.(ts|tsx)$/,
145-
loader: require.resolve('tslint-loader'),
146-
enforce: 'pre',
147-
include: paths.appSrc,
148-
},
149142
{
150143
test: /\.js$/,
151144
loader: require.resolve('source-map-loader'),
@@ -167,11 +160,19 @@ module.exports = {
167160
name: 'static/media/[name].[hash:8].[ext]',
168161
},
169162
},
170-
//Compile .tsx?
163+
// Compile .tsx?
171164
{
172165
test: /\.(ts|tsx)$/,
173166
include: paths.appSrc,
174-
loader: require.resolve('ts-loader')
167+
use: [
168+
{
169+
loader: require.resolve('ts-loader'),
170+
options: {
171+
// disable type checker - we will use it in fork plugin
172+
transpileOnly: true,
173+
},
174+
},
175+
],
175176
},
176177
// The notation here is somewhat confusing.
177178
// "postcss" loader applies autoprefixer to our CSS.
@@ -341,6 +342,12 @@ module.exports = {
341342
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
342343
// You can remove this if you don't use Moment.js:
343344
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
345+
// Perform type checking and linting in a separate process to speed up compilation
346+
new ForkTsCheckerWebpackPlugin({
347+
async: false,
348+
tsconfig: paths.appTsConfig,
349+
tslint: paths.appTsLint,
350+
}),
344351
],
345352
// Some libraries import Node modules but don't use them in the browser.
346353
// Tell Webpack to provide empty mocks for them so importing them works.

packages/react-scripts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"dotenv": "4.0.0",
2929
"extract-text-webpack-plugin": "3.0.0",
3030
"file-loader": "0.11.2",
31+
"fork-ts-checker-webpack-plugin": "^0.2.8",
3132
"fs-extra": "3.0.1",
3233
"html-webpack-plugin": "2.29.0",
3334
"jest": "20.0.4",
@@ -40,7 +41,6 @@
4041
"ts-jest": "^20.0.7",
4142
"ts-loader": "^2.2.1",
4243
"tslint": "^5.2.0",
43-
"tslint-loader": "^3.5.3",
4444
"tslint-react": "^3.0.0",
4545
"typescript": "~2.4.0",
4646
"source-map-loader": "^0.2.1",

0 commit comments

Comments
 (0)