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

Commit 923b627

Browse files
authored
Merge pull request #165 from johnnyreilly/master
Add support for fork-ts-checker-webpack-plugin
2 parents bdc024d + 91d74f0 commit 923b627

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

packages/react-scripts/config/paths.js

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = {
5959
testsSetup: resolveApp('src/setupTests.ts'),
6060
appNodeModules: resolveApp('node_modules'),
6161
appTsConfig: resolveApp('tsconfig.json'),
62+
appTsLint: resolveApp('tslint.json'),
6263
publicUrl: getPublicUrl(resolveApp('package.json')),
6364
servedPath: getServedPath(resolveApp('package.json')),
6465
};
@@ -81,6 +82,7 @@ module.exports = {
8182
appNodeModules: resolveApp('node_modules'),
8283
appTsConfig: resolveApp('tsconfig.json'),
8384
appTsTestConfig: resolveApp('tsconfig.test.json'),
85+
appTsLint: resolveApp('tslint.json'),
8486
publicUrl: getPublicUrl(resolveApp('package.json')),
8587
servedPath: getServedPath(resolveApp('package.json')),
8688
// These properties only exist before ejecting:
@@ -112,6 +114,7 @@ if (
112114
testsSetup: resolveOwn('template/src/setupTests.ts'),
113115
appNodeModules: resolveOwn('node_modules'),
114116
appTsConfig: resolveOwn('template/tsconfig.json'),
117+
appTsLint: resolveOwn('template/tslint.json'),
115118
appTsTestConfig: resolveOwn('template/tsconfig.test.json'),
116119
publicUrl: getPublicUrl(resolveOwn('package.json')),
117120
servedPath: getServedPath(resolveOwn('package.json')),

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

+17-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1616
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1717
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
1818
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
19+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
1920
const getClientEnvironment = require('./env');
2021
const paths = require('./paths');
2122

@@ -120,14 +121,6 @@ module.exports = {
120121
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
121122
// { parser: { requireEnsure: false } },
122123

123-
// First, run the linter.
124-
// It's important to do this before Babel processes the JS.
125-
{
126-
test: /\.(ts|tsx)$/,
127-
loader: require.resolve('tslint-loader'),
128-
enforce: 'pre',
129-
include: paths.appSrc,
130-
},
131124
{
132125
test: /\.js$/,
133126
loader: require.resolve('source-map-loader'),
@@ -154,7 +147,15 @@ module.exports = {
154147
{
155148
test: /\.(ts|tsx)$/,
156149
include: paths.appSrc,
157-
loader: require.resolve('ts-loader'),
150+
use: [
151+
{
152+
loader: require.resolve('ts-loader'),
153+
options: {
154+
// disable type checker - we will use it in fork plugin
155+
transpileOnly: true,
156+
},
157+
},
158+
],
158159
},
159160
// Process JS with Babel.
160161
{
@@ -264,6 +265,13 @@ module.exports = {
264265
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
265266
// You can remove this if you don't use Moment.js:
266267
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
268+
// Perform type checking and linting in a separate process to speed up compilation
269+
new ForkTsCheckerWebpackPlugin({
270+
async: false,
271+
watch: paths.appSrc,
272+
tsconfig: paths.appTsConfig,
273+
tslint: paths.appTsLint,
274+
}),
267275
],
268276
// Some libraries import Node modules but don't use them in the browser.
269277
// Tell Webpack to provide empty mocks for them so importing them works.

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

+17-11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ManifestPlugin = require('webpack-manifest-plugin');
1717
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1818
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
1919
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
20+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
2021
const paths = require('./paths');
2122
const getClientEnvironment = require('./env');
2223

@@ -125,15 +126,6 @@ module.exports = {
125126
// TODO: Disable require.ensure as it's not a standard language feature.
126127
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
127128
// { parser: { requireEnsure: false } },
128-
129-
// First, run the linter.
130-
// It's important to do this before Babel processes the JS.
131-
{
132-
test: /\.(ts|tsx)$/,
133-
loader: require.resolve('tslint-loader'),
134-
enforce: 'pre',
135-
include: paths.appSrc,
136-
},
137129
{
138130
test: /\.js$/,
139131
loader: require.resolve('source-map-loader'),
@@ -155,11 +147,19 @@ module.exports = {
155147
name: 'static/media/[name].[hash:8].[ext]',
156148
},
157149
},
158-
//Compile .tsx?
150+
// Compile .tsx?
159151
{
160152
test: /\.(ts|tsx)$/,
161153
include: paths.appSrc,
162-
loader: require.resolve('ts-loader')
154+
use: [
155+
{
156+
loader: require.resolve('ts-loader'),
157+
options: {
158+
// disable type checker - we will use it in fork plugin
159+
transpileOnly: true,
160+
},
161+
},
162+
],
163163
},
164164
// Process JS with Babel.
165165
{
@@ -350,6 +350,12 @@ module.exports = {
350350
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
351351
// You can remove this if you don't use Moment.js:
352352
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
353+
// Perform type checking and linting in a separate process to speed up compilation
354+
new ForkTsCheckerWebpackPlugin({
355+
async: false,
356+
tsconfig: paths.appTsConfig,
357+
tslint: paths.appTsLint,
358+
}),
353359
],
354360
// Some libraries import Node modules but don't use them in the browser.
355361
// 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
@@ -34,6 +34,7 @@
3434
"dotenv": "4.0.0",
3535
"extract-text-webpack-plugin": "3.0.2",
3636
"file-loader": "1.1.5",
37+
"fork-ts-checker-webpack-plugin": "^0.2.8",
3738
"fs-extra": "3.0.1",
3839
"html-webpack-plugin": "2.29.0",
3940
"jest": "20.0.4",
@@ -53,7 +54,6 @@
5354
"ts-jest": "^21.1.4",
5455
"ts-loader": "^3.1.1",
5556
"tslint": "^5.8.0",
56-
"tslint-loader": "^3.5.3",
5757
"tslint-react": "^3.2.0",
5858
"typescript": "~2.6.1",
5959
"source-map-loader": "^0.2.3"

0 commit comments

Comments
 (0)