gpt4 book ai didi

javascript - Webpack 输出两个包 : source is node_modules vs src?

转载 作者:行者123 更新时间:2023-11-30 20:32:48 25 4
gpt4 key购买 nike

我的项目结构:

/src
/module_1
/module_2
/module_3
/... <-- half a dozen other directories
/node_modules
/obscure_1
/obscure_2
/obscure_3
/... <-- half a million other directories

有没有办法自动让 Webpack (3.x) 输出两个包:

  • 仅来自 /src 的文件>
  • 仅从 /src 导入的文件,但从 /node_modules 导入的文件>

我过去所做的是手动选择我的项目使用的 3-4 个主要包(在 /src 中),并将它们单独打包(通过将它们从主包中排除配置的 externals block )。是否可以完全自动化此过程?

最佳答案

如何查看 CommonChunkPlugin有效,它应该可以解决您的问题。

您可以指定来自 node_modules 的所有模块都将在 vendors block 中,并将该配置传递给它:

new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
minChunks: function(module){
return module.context && module.context.includes("node_modules");
}
})

关于javascript - Webpack 输出两个包 : source is node_modules vs src?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50163331/

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