-
Notifications
You must be signed in to change notification settings - Fork 290
/
ForkTsChecker.js
29 lines (28 loc) · 1.01 KB
/
ForkTsChecker.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
// [fork-ts-checher 检查ts类型]
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-webpack-plugin')
/**
* @name fork-ts-checker
* @description 检查ts类型
*/
module.exports = ({ config, resolve }) => {
const fs = require('fs')
return () => {
if (fs.existsSync(resolve('tsconfig.json'))) {
config.plugin('fork-ts-checker')
.use(ForkTsCheckerWebpackPlugin, [{
// 将async设为false,可以阻止Webpack的emit以等待类型检查器/linter,并向Webpack的编译添加错误。
async: false
}])
}
// 将TypeScript类型检查错误以弹框提示
// 如果fork-ts-checker-webpack-plugin的async为false时可以不用
// 否则建议使用,以方便发现错误
config.plugin('ts-notifier')
.use(ForkTsCheckerNotifierWebpackPlugin, [{
title: 'TypeScript',
excludeWarnings: true,
skipSuccessful: true
}])
}
}