diff --git a/config/mp/webpack.config.js b/config/mp/webpack.config.js index 879a437..fce1239 100644 --- a/config/mp/webpack.config.js +++ b/config/mp/webpack.config.js @@ -11,7 +11,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const ForkTsCheckerWebpackPlugin = process.env.TSC_COMPILE_ON_ERROR === 'true' - ? require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin') + ? require('./../../plugins/ForkTsCheckerWarningWebpackPlugin') : require('react-dev-utils/ForkTsCheckerWebpackPlugin'); const OakWeChatMpPlugin = require('../../plugins/WechatMpPlugin'); diff --git a/config/web/webpack.config.js b/config/web/webpack.config.js index 37d0ee6..f2e4ed4 100644 --- a/config/web/webpack.config.js +++ b/config/web/webpack.config.js @@ -22,7 +22,7 @@ const getClientEnvironment = require('./env'); const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin'); const ForkTsCheckerWebpackPlugin = process.env.TSC_COMPILE_ON_ERROR === 'true' - ? require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin') + ? require('./../../plugins/ForkTsCheckerWarningWebpackPlugin') : require('react-dev-utils/ForkTsCheckerWebpackPlugin'); const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); @@ -681,9 +681,7 @@ module.exports = function (webpackEnv) { javascriptEnabled: true, modifyVars: oakConfigJson.theme, }; - }, - } ), }, diff --git a/plugins/ForkTsCheckerWarningWebpackPlugin.js b/plugins/ForkTsCheckerWarningWebpackPlugin.js new file mode 100644 index 0000000..4b5bb5f --- /dev/null +++ b/plugins/ForkTsCheckerWarningWebpackPlugin.js @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict'; + +// References: +// - https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#plugin-hooks +// - https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/232#issuecomment-645543747 +const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); + +module.exports = class ForkTsCheckerWarningWebpackPlugin { + constructor(options) { + this.options = options; + } + apply(compiler) { + new ForkTsCheckerWebpackPlugin(this.options).apply(compiler); + + const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler); + + hooks.issues.tap('ForkTsCheckerWarningWebpackPlugin', issues => + issues.map(issue => ({ ...issue, severity: 'warning' })) + ); + } +};