[Webpack 2] Grouping vendor files with the Webpack CommonsChunkPlugin
webpack The with Files vendor grouping
2023-09-14 09:00:53 时间
Often, you have dependencies which you rarely change. In these cases, you can leverage the CommonsChunkPlugin to automatically put these modules in a separate bundled file so they can be cached and loaded separately from the rest of your code (leveraging the browser cache much more effectively).
The libaraies like 'lodash', 'jquery' are required alomost all the projects and once download, rarly change any more. So it would be a good idea to spreate those common libaries into a common vendor file.
entry: { app: './js/app.js', vendor: ['lodash', 'jquery'], },
So rename the entry, add 'app' and 'vendor' entries.
So the output file canbe named like 'bundle.app.js' and 'bundle.vendor.js':
output: { filename: 'bundle.[name].js', path: resolve(__dirname, 'dist'), pathinfo: true, },
We will use webpack build in CommonsChunkPlugin:
plugins: [ isTest ? undefined : new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', }), ].filter(p => !!p),
Now we can include those two bundle files into index.html:
<script src="/bundle.vendor.js"></script> <script src="/bundle.app.js"></script>
相关文章
- 入门webpack的最佳实践(基于webpack4.X 5.X)-- postcss-loader介绍
- webpack(10)webpack-dev-server搭建本地服务器「建议收藏」
- webpack打包原理分析和实现(二)
- webpack高级配置
- Webpack相关基础
- ESM 是如何被 webpack 打包成 CommonJS 格式的
- 比 Vite 快 10 倍的 Turbopack!?Webpack 的继承者。
- 彻底搞懂 Webpack 的 sourcemap 配置原理
- 教你手写webpack常用loader
- 【错误记录】Android Studio 创建报错 ( The length of the module location exceeds the limit of 100 characters. )
- ORA-01378: The logical block size (string) of file string is not compatible with the disk sector size (media sector size is string and host sector size is string) ORACLE 报错 故障修复 远程处理
- ORA-22955: The cardinality parameter is not within the allowed limits ORACLE 报错 故障修复 远程处理
- ORA-26748: The one-to-one transformation function string encountered the following error: string ORACLE 报错 故障修复 远程处理
- ORA-31053: The value of the depth argument in the operator cannot be negative ORACLE 报错 故障修复 远程处理
- ORA-31128: The event handler calls cannot exceed the depth of string ORACLE 报错 故障修复 远程处理
- ORA-31691: The worker received message number string from the MCP, which is invalid. ORACLE 报错 故障修复 远程处理
- ORA-31692: The following SQL statement failed trying to insert a row into the Master table: string ORACLE 报错 故障修复 远程处理
- ORA-46011: The value of the “selectPrivilege” element is too long. ORACLE 报错 故障修复 远程处理
- ORA-48409: The ADR homes exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48410: The trace path exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48412: The parameters exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-53254: The SOP INSTANCE UID for the new DICOM object is invalid. ORACLE 报错 故障修复 远程处理
- ORA-13614: The template string is not compatible with the current advisor. ORACLE 报错 故障修复 远程处理
- ORA-13621: The task_or object string is marked as a template and cannot perform the requested operation. ORACLE 报错 故障修复 远程处理
- Oracle介绍The函数的应用(oracle the函数)