解决chunk-vendors.js文件太大,首屏加载很慢

embedded/2024/10/10 21:34:05/

首先介绍一款插件script-ext-html-webpack-plugin
可以动态插入script标签到HTML模板文件中,帮助开发者更好地控制脚本的加载和执行顺序,从而提高页面性能和用户体验。此外,该插件还允许开发者将JavaScript文件分为不同的块(chunk)并在HTML文件中按需引入,以加快页面的加载速度。它允许指定哪些JS文件是内联的,哪些是外部引用的

vue.config.js

chainWebpack(config) {// it can improve the speed of the first screen, it is recommended to turn on preload// it can improve the speed of the first screen, it is recommended to turn on preloadconfig.plugin('preload').tap(() => [{rel: 'preload',// to ignore runtime.js// https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],include: 'initial'}])config.resolve.alias.set('@', resolve('src')).set('vue', resolve('./node_modules/vue'))config.plugin('provide').use(webpack.ProvidePlugin, [{'window.Quill': 'quill/dist/quill.js','Quill': 'quill/dist/quill.js'}])// when there are many pages, it will cause too many meaningless requestsconfig.plugins.delete('prefetch')// set svg-sprite-loaderconfig.module.rule('svg').exclude.add(resolve('src/icons')).end()config.module.rule('icons').test(/\.svg$/).include.add(resolve('src/icons')).end().use('svg-sprite-loader').loader('svg-sprite-loader').options({symbolId: 'icon-[name]'}).end()config.when(['development', 'production'].includes(process.env.NODE_ENV),config => {config.plugin('ScriptExtHtmlWebpackPlugin').after('html').use('script-ext-html-webpack-plugin', [{// `runtime` must same as runtimeChunk name. default is `runtime`inline: /runtime\..*\.js$/}]).end()config.optimization.splitChunks({chunks: 'all',cacheGroups: {libs: {name: 'chunk-libs',test: /[\\/]node_modules[\\/]/,priority: 10,chunks: 'initial' // only package third parties that are initially dependent},elementUI: {name: 'chunk-elementUI', // split elementUI into a single packagepriority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or apptest: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm},commons: {name: 'chunk-commons',test: resolve('src/components'), // can customize your rulesminChunks: 3, //  minimum Common numberpriority: 5,reuseExistingChunk: true}}})// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunkconfig.optimization.runtimeChunk('single')})}

http://www.ppmy.cn/embedded/26312.html

相关文章

ElasticSearch常用操作API

基础操作 以下均为[GET]操作 查看ElasticSearch全部索引 http://{ip}:9200/_cat/indices?v 查看ElasticSearch集群节点 http://{ip}:9200/_cat/nodes?v 查看ElasticSearch版本信息 http://{ip}:9200/ 查看ElasticSearch集群状态 http://{ip}:9200/_cluster/health?pretty …

一文读懂Spring中的@Validated注解

目录 1. 基本知识2. validated和valid差异 1. 基本知识 在Spring框架中,Validated注解用于在方法参数级别上开启方法参数校验的功能 在方法参数上使用JSR-303/JSR-380规范中定义的校验注解,如NotNull、NotBlank、Size等,以对方法参数进行约…

计算机毕业设计python_django宠物领养系统z6rfy

本宠物领养系统主要包括两大功能模块,即管理员模块、用户模块。下面将对这两个大功能进行具体功能需求分析。 (1)管理员:管理员登录后主要功能包括个人中心、用户管理、送养宠物管理、地区类型管理、失信黑名单管理、申请领养管理…

Taro引入echarts【兼容多端小程序(飞书/微信/支付宝小程序)】

近期接到公司新需求,开发飞书小程序,并且原型中含有大量的图表,本想使用飞书内置图表组件 —— chart-space,但官方表示已经停止维护了,无奈之下,只能另寻他路,于是乎,图表之王&…

私域流量运营平台:助力企业实现用户转化与营销新突破

​在当今数字化时代,私域流量运营已成为企业营销的重要一环。私域流量运营平台,作为助力企业实现精准营销、提升用户转化的工具,正逐渐受到市场的青睐。本文将详细介绍私域流量运营平台的功能、特点、优势、适用场景及使用方法,帮…

selenium-webdriver 设置宽高 node

在使用 Node.js 的 Selenium WebDriver 进行自动化测试时,你可能会需要为浏览器窗口设置特定的宽度和高度。以下是如何设置浏览器窗口大小的示例: 首先,确保你已经安装了 selenium-webdriver 包。如果还没有安装,可以通过运行以下…

Linux的vim下制作进度条

目录 前言: 回车和换行有区别吗? 回车和换行的区别展示(这个我在Linux下演示) 为什么会消失呢? 回车和换行的区别 为什么\r和\n产生的效果不同? 打印进度条: (1)打印字符串 …

Git从旧的仓库迁移到新的仓库后clone lfs的文件出现错误

一、问题描述 利用git转移仓库从gitee的testA.git仓库到coding的testB.git利用命令 git clone --mirror gitgitee.com:dev/testA.git cd testA.git git push --mirror gitgit.e.coding.test.clund:dev/testB.git 可以迁移成功,但是在clone新的仓库时候会发现存在l…