gpt4 book ai didi

javascript - webpack 加载器始终在编译中包含 node_modules

转载 作者:行者123 更新时间:2023-11-28 04:57:07 24 4
gpt4 key购买 nike

我正在使用 webpack 1.13.3,并回复 this question我在底部提供了我的 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) 我尝试同时使用 includeexclude

对于 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 中排除。

关于javascript - webpack 加载器始终在编译中包含 node_modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42457140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com