Skip to content

Commit f511a75

Browse files
committed
Use fork-ts-checker-webpack-plugin instead of tslint-loader
1 parent c7e09cb commit f511a75

13 files changed

Lines changed: 84 additions & 69 deletions

File tree

examples/with-typescript/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
"@types/express": "^4.11.1",
1919
"@types/jest": "^22.2.3",
2020
"@types/node": "9.6.6",
21-
"@types/react": "^16.3.12",
21+
"@types/react": "^16.3.13",
2222
"@types/react-dom": "^16.0.5",
2323
"@types/react-router-dom": "^4.2.6",
2424
"@types/webpack-env": "^1.13.6",
2525
"razzle": "^2.0.0-alpha.12",
2626
"razzle-plugin-typescript": "^2.0.0-alpha.12",
27-
"ts-jest": "^22.4.4",
28-
"tslint": "^5.9.1",
27+
"ts-jest": "^22.4.5",
28+
"tslint": "^5.10.0",
2929
"tslint-react": "^3.5.1",
3030
"typescript": "^2.8.3"
3131
},

examples/with-typescript/src/App.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as React from 'react';
2-
import * as ReactDOM from 'react-dom';
1+
import React from 'react';
2+
import { render } from 'react-dom';
33

44
import App from './App';
55

@@ -8,7 +8,7 @@ import { MemoryRouter } from 'react-router-dom';
88
describe('<App />', () => {
99
test('renders without exploding', () => {
1010
const div = document.createElement('div');
11-
ReactDOM.render(
11+
render(
1212
<MemoryRouter>
1313
<App />
1414
</MemoryRouter>,

examples/with-typescript/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import React from 'react';
22
import { Route, Switch } from 'react-router-dom';
33
import Home from './Home';
44

examples/with-typescript/src/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import React from 'react';
22
import logo from './react.svg';
33

44
import './Home.css';

examples/with-typescript/src/client.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as React from 'react';
2-
import * as ReactDOM from 'react-dom';
1+
import React from 'react';
2+
import { hydrate } from 'react-dom';
33
import { BrowserRouter } from 'react-router-dom';
44

55
import App from './App';
66

7-
ReactDOM.hydrate(
7+
hydrate(
88
<BrowserRouter>
99
<App />
1010
</BrowserRouter>,
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
/* tslint:disable:no-console */
12
import express from 'express';
23
import app from './server';
34

45
if (module.hot) {
5-
module.hot.accept('./server', function() {
6+
module.hot.accept('./server', () => {
67
console.log('🔁 HMR Reloading `./server`...');
78
});
89
console.info('✅ Server-side HMR Enabled!');
@@ -11,8 +12,8 @@ if (module.hot) {
1112
const port = process.env.PORT || 3000;
1213

1314
export default express()
14-
.use((req, res) => app.handle(req, res))
15-
.listen(port, function(err) {
15+
.use(app)
16+
.listen(port, (err: Error) => {
1617
if (err) {
1718
console.error(err);
1819
return;

examples/with-typescript/src/server.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as express from 'express';
2-
import * as React from 'react';
1+
import express from 'express';
2+
import React from 'react';
33
import { renderToString } from 'react-dom/server';
44
import { StaticRouter } from 'react-router-dom';
55

@@ -8,7 +8,7 @@ import App from './App';
88
let assets: any;
99

1010
const syncLoadAssets = () => {
11-
assets = require(process.env.RAZZLE_ASSETS_MANIFEST!);
11+
assets = require(process.env.RAZZLE_ASSETS_MANIFEST!);
1212
};
1313
syncLoadAssets();
1414

examples/with-typescript/tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"no-arg": true,
2727
"no-bitwise": true,
2828
"no-consecutive-blank-lines": true,
29-
"no-console": false,
29+
"no-console": true,
3030
"no-construct": true,
3131
"no-debugger": true,
3232
"no-duplicate-variable": true,

packages/razzle-plugin-typescript/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ npm install --save razzle-plugin-typescript
1010

1111
Using the plugin with the default options
1212

13-
1413
```js
1514
// razzle.config.js
1615

@@ -38,18 +37,19 @@ module.exports = {
3837
// any babel transforms
3938
useBabel: true,
4039

41-
// Any option you want to pass to tslint-loader: https://github.com/wbuchwalter/tslint-loader
42-
tslintLoader: {
40+
// Any option you want to pass to ts-loader: https://github.com/TypeStrong/ts-loader
41+
tsLoader: {
4342
transpileOnly: true,
43+
experimentalWatchApi: true,
4444
},
4545

46-
// Any option you want to pass to ts-loader: https://github.com/TypeStrong/ts-loader
47-
tsLoader: {
48-
emitErrors: true,
46+
// Any option you want to pass to fork-ts-checker-webpack-plugin: https://github.com/Realytics/fork-ts-checker-webpack-plugin
47+
forkTsChecker: {
48+
tsconfig: './tsconfig.json',
49+
tslint: './tslint.json',
50+
watch: './src',
4951
typeCheck: true,
50-
configFile: './tslint.json',
51-
tsConfigFile: './tsconfig.json',
52-
},
52+
}
5353
},
5454
},
5555
],

packages/razzle-plugin-typescript/helpers.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@ const loaderFinder = loaderName => rule => {
44
// i.e.: /eslint-loader/
55
const loaderRegex = new RegExp(`[/\\\\]${loaderName}[/\\\\]`);
66

7+
// Checks if there's a loader string in rule.loader matching loaderRegex.
8+
const inLoaderString =
9+
typeof rule.loader === 'string' && rule.loader.match(loaderRegex);
10+
711
// Checks if there is an object inside rule.use with loader matching loaderRegex, OR
8-
// If there's a loader string in rule.loader matching loaderRegex.
9-
return (
10-
(Array.isArray(rule.use) &&
11-
rule.use.find(
12-
loader =>
13-
typeof loader.loader === 'string' && loader.loader.match(loaderRegex)
14-
)) ||
15-
(typeof rule.loader === 'string' && rule.loader.match(loaderRegex))
16-
);
12+
const inUseArray =
13+
Array.isArray(rule.use) &&
14+
rule.use.find(
15+
loader =>
16+
typeof loader.loader === 'string' && loader.loader.match(loaderRegex)
17+
);
18+
19+
return inUseArray || inLoaderString;
1720
};
1821

19-
const eslintLoaderFinder = loaderFinder('eslint-loader');
2022
const babelLoaderFinder = loaderFinder('babel-loader');
21-
const tslintLoaderFinder = loaderFinder('tslint-loader');
2223
const tsLoaderFinder = loaderFinder('ts-loader');
24+
const eslintLoaderFinder = loaderFinder('eslint-loader');
2325

2426
module.exports = {
2527
eslintLoaderFinder,
2628
babelLoaderFinder,
27-
tslintLoaderFinder,
2829
tsLoaderFinder,
2930
};

0 commit comments

Comments
 (0)