我想在整个解决方案上将警告作为错误政策。启用C#项目很容易,但是我一直在努力使用NodeJS(JavaScript和TypeScript)。
我在Visual Studio解决方案中有一个Web项目。
我的目标是:
使用当前解决方案,我只能部分实现
package.json:
{
....
"scripts": {
"start:localhost": "cross-env REACT_APP_API_URL=http://localhost:5000/restapi REACT_APP_SIGNALR_URL=http://localhost:5000/hub REACT_APP_USE_MOCKS=true react-app-rewired start",
"build": "react-app-rewired build",
"lint": "eslint .",
"analyze": "source-map-explorer build/static/js/main.*",
...
},
}
tsconfig.js:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./tscompiled",
"moduleResolution": "node",
"allowJs": true,
"jsx": "react",
"allowSyntheticDefaultImports": true,
"target": "es6",
"lib": [ "es7", "dom" ]
},
"include": [
"./src/**/*.ts",
"./src/**/*.vue",
"./src/**/*.tsx",
"./typings/**/*"
],
"exclude": [
"./node_modules"
]
}
config-overrides.js
/* eslint-disable */
const path = require('path');
const fs = require('fs');
const rewireBabelLoader = require('react-app-rewire-babel-loader');
const rewireTypescript = require('react-app-rewire-typescript');
var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const WarningsToErrorsPlugin = require('warnings-to-errors-webpack-plugin');
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
function visualStudioErrorFormatter(error) {
//https://blogs.msdn.microsoft.com/msbuild/2006/11/02/msbuild-visual-studio-aware-error-messages-and-message-formats/
//http://www.gnu.org/prep/standards/standards.html#Errors
return (
//Object.keys(error) -> type, code, severity, content, file, line, character
error.file + '(' + error.line + ',' + error.character + ') : ' + error.severity + ' ' + error.code + ':' + error.content
);
}
module.exports = function override(config, env) {
// config = rewireReactHotLoader(config, env);
config = rewireTypescript(config, env);
config = rewireBabelLoader.include(
config,
resolveApp('node_modules/@MyProject/mykit-react/'),
);
var typescriptChecker = new ForkTsCheckerWebpackPlugin();
var warningsToErrorsPlugin = new WarningsToErrorsPlugin();
typescriptChecker.workersNumber = 2;
typescriptChecker.errorFormatter = visualStudioErrorFormatter;
typescriptChecker.formatter = visualStudioErrorFormatter;
config.plugins.push(warningsToErrorsPlugin);
config.plugins.push(typescriptChecker);
config.context = __dirname;
config.entry = './src/index.tsx';
config.module = {
...config.module,
rules: [
...config.module.rules,
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
// disable type checker - we will use it in fork plugin
transpileOnly: true,
}
}
],
};
return config;
};