我有一个带有Webpack的TypeScript项目,package.json
"ts-checker-webpack-plugin": "^0.3.0",
"tslint": "^5.9.1",
"typescript": "^2.8.3",
我还有一个用TypeScript编写的自定义TSLint规则,它在webpack构建期间由tsc
编译,但tslint找不到生成的JS。它输出以下错误:
Could not find implementations for the following rules specified in the configuration: custom-check
我已经确认,如果我手动将customCheckRule.ts
编译为JS,则该规则将由webpack和tslint定位并使用。
如何设置webpack或ts-checker-webpack-plugin
以确保在构建过程中编译和使用规则?
以下是webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
...
module.exports = {
...,
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]
},
plugins: [
...,
new TsCheckerWebpackPlugin({
tsconfig: path.resolve("tsconfig.json"),
tslint: path.resolve("tslint.json"), // optional
memoryLimit: 512, // optional, maximum memory usage in MB
diagnosticFormatter: "ts-loader", // optional, one of "ts-loader", "stylish", "codeframe"
})
],
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
use: [{
loader: 'babel-loader'
}, {
loader: 'ts-loader',
options: {
transpileOnly: true
}
}]
},
...
]
}
};