Skip to content

Commit 679db45

Browse files
Quinn Chaffeejaredpalmer
authored andcommitted
Better defaults for Typescript example (#593)
* Better defaults for Typescript example After running into multiple bugs having to deal with whether typescript was precompiling the same way that the babel version was (some include: jest testing, repl loading, mjs support) I realized that the big issue is that razzle had figured out solutions for each env based on webpack, so instead of having the added complexity of not knowing if I had proper typescript parody, I figured just remove that layer and use typescript for the one thing I wanted: type checking. Happy to go into detail on those bugs, but I think the main point is this approach seems a better DX experiance out of the box, while offering more heavy solutions as comments. * Update razzle.config.js
1 parent 75bcb08 commit 679db45

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

examples/with-typescript/razzle.config.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module.exports = {
88
'.ts',
99
'.tsx',
1010
]);
11+
1112

12-
config.devtool = 'cheap-module-source-map';
1313

1414
// Locate eslint-loader and remove it (we're using tslint instead)
1515
config.module.rules = config.module.rules.filter(
@@ -21,6 +21,17 @@ module.exports = {
2121
'useEslintrc' in rule.use[0].options
2222
)
2323
);
24+
// Add tslint-loader
25+
config.module.rules.push({
26+
include,
27+
enforce: 'pre',
28+
test: /\.tsx?$/,
29+
loader: 'tslint-loader',
30+
options: {
31+
emitErrors: true,
32+
configFile: './tslint.json',
33+
},
34+
});
2435

2536
// Safely locate Babel-Loader in Razzle's webpack internals
2637
const babelLoader = config.module.rules.findIndex(
@@ -40,31 +51,20 @@ module.exports = {
4051
transpileOnly: true,
4152
},
4253
};
43-
44-
const tslintLoader = {
45-
include,
46-
enforce: 'pre',
47-
test: /\.tsx?$/,
48-
loader: 'tslint-loader',
49-
options: {
50-
emitErrors: true,
51-
configFile: './tslint.json',
52-
},
53-
};
54-
55-
config.module.rules.push(tslintLoader);
56-
57-
// Fully replace babel-loader with ts-loader
58-
config.module.rules[babelLoader] = tsLoader;
59-
60-
// If you want to use Babel & Typescript together (e.g. if you
61-
// are migrating incrementally and still need some Babel transforms)
54+
// Add loader
55+
config.module.rules.push(tsLoader)
56+
57+
// Additional options found at https://github.com/TypeStrong/ts-loader#faster-builds
58+
// Add async typechecking errors
59+
// config.plugins.push(new require('fork-ts-checker-webpack-plugin')())
60+
61+
// If you want to replace Babel with typescript to fully speed up build
6262
// then do the following:
6363
//
64-
// - COMMENT out line 59
65-
// - UNCOMMENT line 68
64+
// - COMMENT out line 55
65+
// - UNCOMMENT line 67
6666
//
67-
// config.module.rules.push(tsLoader)
67+
// config.module.rules[babelLoader] = tsLoader;
6868

6969
return config;
7070
},

0 commit comments

Comments
 (0)