我正在使用 webpack 1.13.3,在回答这个问题时,我在底部提供了我的 tsconfig.json。
我的加载器总是包含 node_modules 包,无论我是使用包含、排除还是两者的组合。
网络包配置:
var path = require("path");
module.exports = {
entry: "./src/bootstrap.tsx",
output: {
filename: "./public/dist/bundle.js",
},
// Enable sourcemaps for debugging webpack's output.
devtool: "cheap-module-source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},
module: {
loaders: [
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
{ include: path.resolve(__dirname, "src"), exclude: /node_modules/, test: /\.tsx?$/, loader: "ts-loader" }
],
preLoaders: [
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ test: /\.js$/, loader: "source-map-loader" }
]
},
};
我尝试了各种组合:
1) 仅包含正则表达式/src/
或直接path.resolve(__dirname, "src")
/node_modules/
2) 仅使用正则表达式或直接排除path.resolve(__dirname, "node_modules")
3)我尝试过同时使用两者include
和exclude
.
对于node_modules中的文件,我总是从我的ts-loader中收到错误,即:
ERROR in /path/to/prj/node_modules/@types/enzyme/index.d.ts
(337,22): error TS2304: Cannot find name 'ComponentClass'.
不知道该怎么做,据我所知,加载器配置中的排除/包含假设是向 webpack 指示包含或排除要转换的文件,如何始终包含 node_modules 文件?
编辑 1: 万一这很重要,这是我的 tsconfig.json
{
"compilerOptions": {
"outDir": "./public/dist",
"target": "es5",
"module": "commonjs",
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"jsx": "react"
},
"include": [
"./src/**/*.tsx",
"./src/**/*.ts"
],
"exclude": [
"node_modules"
]
}