-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrazzle.config.js
88 lines (74 loc) · 2.22 KB
/
razzle.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
const { ReactLoadablePlugin } = require('react-loadable/webpack');
module.exports = {
modify(baseConfig, { target, dev }, webpack) {
const config = Object.assign({}, baseConfig);
config.resolve.extensions = config.resolve.extensions.concat([
'.ts',
'.tsx'
]);
config.devtool = 'cheap-module-source-map';
// Locate eslint-loader and remove it (we're using tslint instead)
config.module.rules = config.module.rules.filter(
rule =>
!(
Array.isArray(rule.use) &&
rule.use.length > 0 &&
rule.use[0].options &&
'useEslintrc' in rule.use[0].options
)
);
// Safely locate Babel-Loader in Razzle's webpack internals
const babelLoader = config.module.rules.findIndex(
rule => rule.options && rule.options.babelrc
);
// Get the correct `include` option, since that hasn't changed.
// This tells Razzle which directories to transform.
const { include } = config.module.rules[babelLoader];
// Declare our TypeScript loader configuration
const tsLoader = {
include,
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
// this will make errors clickable in `Problems` tab of VSCode
visualStudioErrorFormat: true,
typeCheck: true
}
};
const tslintLoader = {
include,
enforce: 'pre',
test: /\.tsx?$/,
loader: 'tslint-loader',
options: {
emitErrors: true,
configFile: './tslint.json'
}
};
config.module.rules.push(tslintLoader);
// Fully replace babel-loader with ts-loader
config.module.rules[babelLoader] = tsLoader;
// If you want to use Babel & Typescript together (e.g. if you
// are migrating incrementally and still need some Babel transforms)
// then do the following:
//
// - COMMENT out line 59
// - UNCOMMENT line 68
//
// config.module.rules.push(tsLoader)
// add custom plugins here
if (target === 'web') {
return {
...config,
plugins: [
...config.plugins,
new ReactLoadablePlugin({
filename: './build/react-loadable.json'
})
]
};
}
return config;
}
};