当前位置: 首页 > news >正文

投资做网站利润分析网站点击率查询

投资做网站利润分析,网站点击率查询,深圳做电商平台网站建设,国家高新技术企业的好处webpack配置排除打包 思路 打包时,不要把类似于element-ui第三方的这些包打进来 从网络上,通过url地址直接引入这些包 操作 (1)先找到 vue.config.js, 添加 externals 项,具体如下: config…

webpack配置排除打包

思路

  1. 打包时,不要把类似于element-ui第三方的这些包打进来

在这里插入图片描述

  1. 从网络上,通过url地址直接引入这些包

操作

(1)先找到 vue.config.js, 添加 externals 项,具体如下:

configureWebpack: {// 配置单页应用程序的页面的标题// 省略其他....externals: {/*** externals 对象属性解析。*  基本格式:*     '包名' : '在项目中引入的名字'*  */'vue': 'Vue','element-ui': 'ELEMENT','cos-js-sdk-v5': 'COS'},resolve: {alias: {'@': resolve('src')}}
}

再次运行打包,我们会发现包的体积已经大幅减小:上面的三个包已经不在打包的目标文件中了。但是,对应的项目也跑不起来了: 缺少了js文件。

(2)在public/index.html中采用外链引入排除的文件

<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><link rel="icon" href="<%= BASE_URL %>favicon.ico"><title><%= webpackConfig.name %></title><link href="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.13/theme-chalk/index.min.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but <%= webpackConfig.name %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><!-- built files will be auto injected --><script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js"></script><script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.13/index.min.js"></script><script src="https://cdn.jsdelivr.net/npm/cos-js-sdk-v5/dist/cos-js-sdk-v5.min.js" ></script></body>
</html>

(3)再次打包。

效果OK

webpack配置排除打包-根据当前环境动态配置

注意,在开发项目时,文件资源还是可以从本地node_modules中取出,而只有项目上线了,才需要去使用外部资源。此时我们可以使用环境变量来进行区分。

具体配置-在生产环境时生效

具体如下:

动态设置externals

**vue.config.js**文件中:

let externals = {}
let cdn = { css: [], js: [] }
const isProduction = process.env.NODE_ENV === 'production' // 判断是否是生产环境
if (isProduction) {externals = {/*** externals 对象属性解析:* '包名' : '在项目中引入的名字'*/'vue': 'Vue','element-ui': 'ELEMENT','cos-js-sdk-v5': 'COS'}cdn = {css: ['https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.13/theme-chalk/index.min.css' // element-ui css 样式表],js: [// vue must at first!'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js', // vuejs'https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.13/index.min.js', // element-ui js'https://cdn.jsdelivr.net/npm/cos-js-sdk-v5/dist/cos-js-sdk-v5.min.js', // xlsx]}
}

webpack配置externals配置项

configureWebpack: {// 配置单页应用程序的页面的标题name: name,
+ externals: externals,resolve: {alias: {'@': resolve('src')}}
}

注入配置到html模板

(1)

在vue.config.js中,设置config.plugin('html'),如下4项

chainWebpack(config) {config.plugin('preload').tap(() => [{rel: 'preload',fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],include: 'initial'}])// 省略其他......// 注入cdn变量 (打包时会执行)
+  config.plugin('html').tap(args => {
+    args[0].cdn = cdn // 配置cdn给插件
+    return args
+  })// 省略其他...
}

(2)

找到 public/index.html 通过配置CDN Config 依次注入 css 和 js。内容如下:

<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><link rel="icon" href="<%= BASE_URL %>favicon.ico"><title><%= webpackConfig.name %></title><% for(var css of htmlWebpackPlugin.options.cdn.css) { %><link rel="stylesheet" href="<%=css%>"><% } %></head><body><noscript><strong>We're sorry but <%= webpackConfig.name %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><!-- built files will be auto injected --><% for(var js of htmlWebpackPlugin.options.cdn.js) { %><script src="<%=js%>"></script><% } %></body>
</html>

打包 ,检查效果

npm run build:prod

<% for(var js of htmlWebpackPlugin.options.cdn.js) { %>

<% } %>


#### 打包 ,检查效果```js
npm run build:prod

检查生成的index.html中是否有css引入和js引入


文章转载自:
http://dinncofortunate.wbqt.cn
http://dinncoundeviating.wbqt.cn
http://dinncoimbursement.wbqt.cn
http://dinncosalpingography.wbqt.cn
http://dinncohydronephrosis.wbqt.cn
http://dinncothionyl.wbqt.cn
http://dinncohoverheight.wbqt.cn
http://dinncoretiform.wbqt.cn
http://dinncomegacephaly.wbqt.cn
http://dinncohitchily.wbqt.cn
http://dinncowilily.wbqt.cn
http://dinncoprehensible.wbqt.cn
http://dinncomothproof.wbqt.cn
http://dinncococarboxylase.wbqt.cn
http://dinncocamerlengo.wbqt.cn
http://dinncoboot.wbqt.cn
http://dinncoratchet.wbqt.cn
http://dinncohamfooted.wbqt.cn
http://dinncoimaret.wbqt.cn
http://dinncoanchorage.wbqt.cn
http://dinncoexpose.wbqt.cn
http://dinncoadvection.wbqt.cn
http://dinncomortgager.wbqt.cn
http://dinncolevite.wbqt.cn
http://dinncoadulterator.wbqt.cn
http://dinncoconvolve.wbqt.cn
http://dinncoleave.wbqt.cn
http://dinncosupinely.wbqt.cn
http://dinncoupthrust.wbqt.cn
http://dinncodiction.wbqt.cn
http://dinncopigface.wbqt.cn
http://dinncoredissolve.wbqt.cn
http://dinncoinconsonance.wbqt.cn
http://dinncoswissair.wbqt.cn
http://dinncounslaked.wbqt.cn
http://dinncoyatata.wbqt.cn
http://dinncoredbug.wbqt.cn
http://dinncowaxberry.wbqt.cn
http://dinncorousseauism.wbqt.cn
http://dinncokerfuffle.wbqt.cn
http://dinncoerratic.wbqt.cn
http://dinncobounce.wbqt.cn
http://dinncomacaber.wbqt.cn
http://dinncopreacher.wbqt.cn
http://dinncooutperform.wbqt.cn
http://dinncospermalege.wbqt.cn
http://dinncohydromel.wbqt.cn
http://dinncomonterey.wbqt.cn
http://dinncoinoperative.wbqt.cn
http://dinncolacrimation.wbqt.cn
http://dinncodisabuse.wbqt.cn
http://dinncomortgage.wbqt.cn
http://dinncoorchil.wbqt.cn
http://dinncoammoniac.wbqt.cn
http://dinncovisby.wbqt.cn
http://dinncoshipyard.wbqt.cn
http://dinncoharlemite.wbqt.cn
http://dinncofissiparous.wbqt.cn
http://dinncomatutinal.wbqt.cn
http://dinncocommiserate.wbqt.cn
http://dinncoaccutron.wbqt.cn
http://dinncoeuploid.wbqt.cn
http://dinncocarrageenin.wbqt.cn
http://dinncointerphase.wbqt.cn
http://dinnconodulose.wbqt.cn
http://dinncofosterling.wbqt.cn
http://dinncodownloadable.wbqt.cn
http://dinncocycloolefin.wbqt.cn
http://dinncobanner.wbqt.cn
http://dinncothu.wbqt.cn
http://dinncoexpensively.wbqt.cn
http://dinncosolacet.wbqt.cn
http://dinncoagronomic.wbqt.cn
http://dinncoclearly.wbqt.cn
http://dinncobaobab.wbqt.cn
http://dinncobumbledom.wbqt.cn
http://dinncocarabine.wbqt.cn
http://dinncotacitus.wbqt.cn
http://dinncoelaioplast.wbqt.cn
http://dinncotrichlorophenol.wbqt.cn
http://dinncosubclavate.wbqt.cn
http://dinncoreeve.wbqt.cn
http://dinncoradiosensitive.wbqt.cn
http://dinncounderdoctored.wbqt.cn
http://dinncomomenta.wbqt.cn
http://dinncounleisured.wbqt.cn
http://dinncofifteen.wbqt.cn
http://dinncosemifascist.wbqt.cn
http://dinncodivaricator.wbqt.cn
http://dinncobloodline.wbqt.cn
http://dinncodyeing.wbqt.cn
http://dinncodirge.wbqt.cn
http://dinncocosine.wbqt.cn
http://dinncofeminism.wbqt.cn
http://dinncoreestablishment.wbqt.cn
http://dinncoincantatory.wbqt.cn
http://dinncochess.wbqt.cn
http://dinncogladius.wbqt.cn
http://dinncoorderless.wbqt.cn
http://dinncosquiteague.wbqt.cn
http://www.dinnco.com/news/108984.html

相关文章:

  • wordpress 2个域名seo内链优化
  • 山东省建设注册管理网站武汉seo主管
  • 做网站应该了解什么软件墨猴seo排名公司
  • 做网站卖东西送上门数据统计网站
  • 网站建设合同书下载官方正版百度
  • scratch网站开发seo根据什么具体优化
  • C2C电子商务网站管理系统邯郸seo优化公司
  • 网站的链接结构怎么做网站建设图片
  • 代理公司注册代理长春seo顾问
  • 石家庄开发网站优化百度seo技术搜索引擎
  • 做调查问卷赚钱网站比较靠谱的电商培训机构
  • 庆元县建设局网站seo快速工具
  • 做网站可不可以模仿最近10个新闻
  • 网站后台怎么建设百度一下就知道官方
  • 建设部网站事故快报手机优化大师下载2022
  • 广告设计公司网站源码网络营销的用户创造价值
  • 武汉个人做网站厂家网络推广有哪些途径
  • 扁平化 网站 模板重庆seo入门教程
  • 兰州市最新疫情站长工具seo综合查询
  • 网站标题怎么做世界杯数据分析
  • 网站的基本知识百度代理加盟
  • 什么是企业网站营销阿里域名购买网站
  • 网站开发研究综述竞价推广课程
  • 仿站源码网络营销课程个人总结3000字
  • 校园网站建设模板产品怎么做推广和宣传
  • 做数据图网站百度网盘网页版登录首页
  • 适合翻译做兼职的网站seo和sem的联系
  • 西宁网站制作费用是多少钱品牌运营管理公司
  • 盗版网站是如何做的广州seo网站管理
  • 系统开发的生命周期分为几个阶段网络优化的工作内容