在 Webpack 配置中的 Babel-loader 中添加一个选项 exclude 去除不必要的依赖。例如:
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules\/(?![@mycompany])/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
上述代码中,exclude 的正则表达式过滤了所有不在 "@mycompany" 命名空间下的 node_modules。这样做可以解决 Babel-loader 破坏源代码地图的问题。