我正在使用 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")
2)只排除使用正则表达式/node_modules/
或直接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"
]
}
我正在使用 TypeScript 2.0.3 并将其更新到 2.2 修复了它出现的这个问题。现在 node_modules 被排除在 webpack ts-loader 之外。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句