govendor的使用,单独添加某一个包的命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你的问题是关于使用 webpack 将 splitChunks、axios 和 lodash 单独,其他库文件打到 vendor 组的方法。下面是一个示例 webpack 配置文件,你可以参考一下: ``` const path = require('path'); const webpack = require('webpack'); module.exports = { entry: { main: './src/index.js' }, output: { filename: '[name].[chunkhash].js', path: path.resolve(__dirname, 'dist') }, optimization: { splitChunks: { cacheGroups: { vendor: { test: /[\\/]node_modules[\\/]/, name: 'vendor', chunks: 'all' }, axios: { test: /[\\/]node_modules[\\/]axios[\\/]/, name: 'axios', chunks: 'all' }, lodash: { test: /[\\/]node_modules[\\/]lodash[\\/]/, name: 'lodash', chunks: 'all' } } } }, plugins: [ new webpack.ProgressPlugin() ] }; ``` 上述配置文件中,我们使用 optimization.splitChunks.cacheGroups 配置项来定义不同的缓存组。其中,vendor 缓存组用于打其他库文件,而 axios 和 lodash 缓存组则用于单独 axios 和 lodash 库。 在每个缓存组中,我们可以使用 test 字段来匹配需要打的模块。比如,使用 /[\\/]node_modules[\\/]/ 表示打所有在 node_modules 目录下的模块。同时,我们还可以使用 name 字段来指定后的文件名,chunks 字段来指定使用哪些代码块进行打。 最后,我们将 optimization.splitChunks.cacheGroups.vendor 缓存组作为公共模块来打其他库文件,而 axios 和 lodash 缓存组则单独对应的库文件。这样做可以有效减少打后的文件大小,提高页面加载速度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值