diff --git a/160.bundle.js b/160.bundle.js new file mode 100644 index 0000000..21505f4 --- /dev/null +++ b/160.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkcboy_blog=self.webpackChunkcboy_blog||[]).push([[160],{160:function(s,t,e){e.r(t),e.d(t,{default:function(){return u}});var h=e(358);const c={class:"component-postcss-plugin"},o={};var u=(0,e(389).A)(o,[["render",function(s,t){return(0,h.uX)(),(0,h.CE)("div",c,t[0]||(t[0]=[(0,h.Fv)('

写 css 遇到了问题怎么办?

如何让 css 写的更轻松?

postcss-ui-theme,让你实现类 sass 语法,一个插件就能做到!

如何改变 css 主题 ?

postcss-ui-theme , 可打包 css4 变量被保留,不仅可在引用时直接使用新的变量文件覆盖改变主题,还可以通过 js 进行更改!!!

css 在别的项目被编译,文件路径找不到?

postcss-ui-theme, 集成 postcss-assets 插件,通过配置 文件查找路径,解决引用文件找不到问题!!

postcss-ui-theme 插件,就是你的 css 管理方案的最佳选择! 点 star 收藏!!! 茫茫前端路,你真的会用到它的!

',8)]))}]])}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMTYwLmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoiNktBQWVBLE1BQU0sNEJDQ2ZDLEVBQVMsQ0FBQyxFQUtoQixPQUZpQyxFLE9BQUEsR0FBZ0JBLEVBQVEsQ0FBQyxDQUFDLFMsZ0NESmpEQyxFQUFBQSxFQUFBQSxJQVFKLE1BUklDLEVBUUpDLEVBQUEsS0FBQUEsRUFBQSxLQVJOQyxFQUFBQSxFQUFBQSxJQUFBLDZuQiIsInNvdXJjZXMiOlsid2VicGFjazovL2Nib3ktYmxvZy8uLi8uLi9ibG9ncy9tYXJrZG93bi9wb3N0Y3NzLXBsdWdpbi5tZCIsIndlYnBhY2s6Ly9jYm95LWJsb2cvLi4vLi4vYmxvZ3MvbWFya2Rvd24vcG9zdGNzcy1wbHVnaW4ubWQ/ZDZjZCJdLCJzb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Um9vdCI6IiJ9 \ No newline at end of file diff --git a/165.bundle.js b/165.bundle.js new file mode 100644 index 0000000..996e522 --- /dev/null +++ b/165.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkreact_wyz=self.webpackChunkreact_wyz||[]).push([[165],{165:(n,s,e)=>{e.r(s),e.d(s,{default:()=>c});const c="### 什么是 SSL 证书\n\nSSL 证书是数字证书,是由证书认证机构(CA)对证书申请者真实身份验证之后,用CA的根证书对申请人的一些基本信息以及申请人的公钥进行签名(相当于加盖发证书机构的公章)后形成的一个数字文件。\n通俗一点, 就是包含了所使用的服务器的信息和公钥,这些信息是公开的。 而私钥是由证书申请者自己保存的,是保密的。\n\n\n### 怎么配置呢\n\n要在服务器要发送SSL证书,那么在服务器上配置。首先你得有一个`证书`!\n证书如何获取,我也是百度了很多,也有很多免费的网站,ssl for free, freessl.org, 但是发现证书没有.crt 文件,或者验证域名不方便。\n\n######这里先讲一下 SSL 证书包含的几个文件:\n`.key` => 私钥\n`.csr` => 公钥,让你的证书去认证的时,可以把它发送给权威机构认证。\n`.crt ` => 证书了\n\n这里可以自己去体验一下用 OpenSSL 给自己生成一个证书。需自行安装 openssl 软件\n[openssl 给自己颁发证书的步骤](https://www.cnblogs.com/yjmyzz/p/openssl-tutorial.html)\n\nopenssl 的证书既然是自己给自己颁发的,那么就不具有权威性,在连接时会向客户端提示不是安全的链接。也没有小绿锁。\n\n最后我发现腾讯云有免费的证书可以用。\n![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/6c5cab65c69586f9228ecf2896a12ad0.jpeg) \n\n申请好证书之后, 如图\n![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/6aa539ccc93a564348a6b975a998cf80.jpeg)\n点击详情可以看到 [指引文档](https://cloud.tencent.com/document/product/400/4143), 里面的服务器配置方法就很全面了, 不管你是不是用它的证书,都可以按照这样去配。\n\n### 了解一下 SSL 工作\n\n我们知道,在客户端和服务器之间的请求,就是来回发送数据,普通的 HTTP 协议是没有对数据进行加密的,那么可能被第三方截取到你的请求,改变你们的通信数据或者冒充身份发送信息给你。 哇,突然感觉这些很常见 = = \n\nHTTPS 就是一种安全的通信了,它会加密你的数据, 使第三方无法获取,并在建立通信的握手阶段,互相确认身份, 使别人无法冒充身份。 SSL 证书就是使用在 握手阶段,通过证书的信息,确认服务器身份。\n具体如下:\n\n![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/29104c17fe7cebb091ec79ad1714bc32.png)\n\n详细讲解每一步就是:\n第一步:客户端 say hello, 向服务端发送自己生成的 random 数,和自己支持的加密方法。\n\n第二步:服务端接收消息后,又向客户端发送自己生成的 random 数、SSL 证书,确定使用的加密方法。\n\n第三步:客户端读取证书信息,确认证书有效,然后自己再生成一个 random 数,并使用证书的公钥进行加密,发送给服务端。\n\n第四步:服务端使用自己本地的私钥,解密获取客户端的随机数。\n\n第五步:客户端和服务端使用这三个随机数生成 `对话密钥`, 用来加密接下来的对话过程。\n\n可以看到下面英文有提到 session。 因为如果每次建立连接都去进行这五步,那么会很浪费时间。 所以这里有 sessionID 和 session ticket 两种。\n\nsession ID,记录有本次的握手存在,再次发送信息时,客户端发送该ID,服务器确认该编号存在,双方就不再进行握手阶段剩余的步骤,而直接用已有的对话密钥进行加密通信。\n\nsession ID是目前所有浏览器都支持的方法,但是它的缺点在于session ID往往只保留在一台服务器上。所以,如果客户端的请求发到另一台服务器,就无法恢复对话。session ticket就是为了解决这个问题而诞生的,目前只有Firefox和Chrome浏览器支持。session ticket是加密的,只有服务器才能解密,其中包括本次对话的主要信息,比如对话密钥和加密方法。当服务器收到session ticket以后,解密后就不必重新生成对话密钥了。\n"}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMTY1LmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoia0lBQUEsZzdEIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vcmVhY3Rfd3l6Ly4uLy4uL2Jsb2dzL21hcmtkb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Fb6L+Z6YeM5YaZ5Zu+54mH5o+P6L+wXShodHRwczovL2ktYmxvZy5jc2RuaW1nLmNuL2Jsb2dfbWlncmF0ZS82YWE1MzljY2M5M2E1NjQzNDhhNmI5NzVhOTk4Y2Y4MC5qcGVnKVxcbueCueWHu+ivpuaDheWPr+S7peeci+WIsCBb5oyH5byV5paH5qGjXShodHRwczovL2Nsb3VkLnRlbmNlbnQuY29tL2RvY3VtZW50L3Byb2R1Y3QvNDAwLzQxNDMpLCDph4zpnaLnmoTmnI3liqHlmajphY3nva7mlrnms5XlsLHlvojlhajpnaLkuoYsIOS4jeeuoeS9oOaYr+S4jeaYr+eUqOWug+eahOivgeS5pu+8jOmDveWPr+S7peaMieeFp+i/meagt+WOu+mFjeOAglxcblxcbiMjIyDkuobop6PkuIDkuIsgU1NMIOW3peS9nFxcblxcbuaIkeS7rOefpemBk++8jOWcqOWuouaIt+err+WSjOacjeWKoeWZqOS5i+mXtOeahOivt+axgu+8jOWwseaYr+adpeWbnuWPkemAgeaVsOaNru+8jOaZrumAmueahCBIVFRQIOWNj+iuruaYr+ayoeacieWvueaVsOaNrui/m+ihjOWKoOWvhueahO+8jOmCo+S5iOWPr+iDveiiq+esrOS4ieaWueaIquWPluWIsOS9oOeahOivt+axgu+8jOaUueWPmOS9oOS7rOeahOmAmuS/oeaVsOaNruaIluiAheWGkuWFhei6q+S7veWPkemAgeS/oeaBr+e7meS9oOOAgiDlk4fvvIznqoHnhLbmhJ/op4nov5nkupvlvojluLjop4EgPSA9IFxcblxcbkhUVFBTICDlsLHmmK/kuIDnp43lronlhajnmoTpgJrkv6HkuobvvIzlroPkvJrliqDlr4bkvaDnmoTmlbDmja7vvIwg5L2/56ys5LiJ5pa55peg5rOV6I635Y+W77yM5bm25Zyo5bu656uL6YCa5L+h55qE5o+h5omL6Zi25q6177yM5LqS55u456Gu6K6k6Lqr5Lu977yMIOS9v+WIq+S6uuaXoOazleWGkuWFhei6q+S7veOAgiBTU0wg6K+B5Lmm5bCx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zmo5omN6IO96Kej5a+G77yM5YW25Lit5YyF5ous5pys5qyh5a+56K+d55qE5Li76KaB5L+h5oGv77yM5q+U5aaC5a+56K+d5a+G6ZKl5ZKM5Yqg5a+G5pa55rOV44CC5b2T5pyN5Yqh5Zmo5pS25Yiwc2Vzc2lvbiB0aWNrZXTku6XlkI7vvIzop6Plr4blkI7lsLHkuI3lv4Xph43mlrDnlJ/miJDlr7nor53lr4bpkqXkuobjgIJcXG5cIjsiXSwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/167.bundle.js b/167.bundle.js new file mode 100644 index 0000000..4a559b0 --- /dev/null +++ b/167.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkreact_wyz=self.webpackChunkreact_wyz||[]).push([[167],{167:(n,e,t)=>{t.r(e),t.d(e,{default:()=>o});const o="vue 是一个 js 框架,它实现了自己的模板,通过 .vue 文件可以经过编译成一个数据改变驱动视图改变的 js代码。\n那么这其中又是经历了什么样的步骤呢?\n\n----- \n一个 vue 对象是通过 new Vue({options}) 来得到的,也就是构造函数了。我们来看这个函数\n```\nfunction Vue (options) {\n if (process.env.NODE_ENV !== 'production' &&\n !(this instanceof Vue)\n ) {\n warn('Vue is a constructor and should be called with the `new` keyword')\n }\n this._init(options)\n}\n\n// 这里是一系列对这个函数进行的继承\ninitMixin(Vue)\nstateMixin(Vue)\neventsMixin(Vue)\nlifecycleMixin(Vue)\nrenderMixin(Vue)\n\nexport default Vue\n```\n可以看到这个 Vue 构造函数,它经历了 5 个系列的mixin,并在新创建时会运行 _init(options) 方法。\n那么我们来看看, 这五个 mixin 分别做了啥。\n\n ##### 第一个 initMixin\n 它只做了一件事, 定义了 _init 方法,那么你就知道创造一个Vue 实例,它执行的 _init 方法就是上面这个方法了。\n```\nVue.prototype._init = function (options?: Object) {\n....\n}\n```\n\n\n\n##### 第二个 stateMixin \n```\n Object.defineProperty(Vue.prototype, '$data', dataDef) // 能够返回 data\n Object.defineProperty(Vue.prototype, '$props', propsDef) // 能够返回 props\n Vue.prototype.$set = set // 就是我们用的 this.$set(this.people, 'name', ‘clever')方法, 下同。\n Vue.prototype.$delete = del\n Vue.prototype.$watch = function (\n ....\n }\n ```\n\n##### 第三个 eventsMixin\n```\nVue.prototype.$on = function (eventname, fn) {\n....\n}\nVue.prototype._$once = function (eventname, fn) {\n // 监听一个自定义事件,但是只触发一次,在第一次触发之后移除监听器。\n}\nVue.prototype._off = function (event, fn) {\n// 移除自定义事件监听器。\n}\nVue.prototype.$emit = function (event) {\n// 触发一个事件\n}\n```\n##### 第四个 lifecycleMixin![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0227c8c15285fbd179573e7cd8cb4718.png)\n##### 第五个 renderMixin![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/715399a9ac35cef7c3aca2d3242ca5a3.png)\n---\n\n好, 这个 Vue 继承了这些方法,它已经是一个完整的 Vue 了,而新创建的时候要执行 _init 方法了, 现在我们来看看这个方法里面做了写啥\n- vm._uid = uid++ 创建 uid\n- 合并 options\n- initLifecycle\n initEvents(vm)\n initRender(vm)\n callHook(vm, 'beforeCreate')\n initInjections(vm) // resolve injections before data/props\n initState(vm)\n initProvide(vm) // resolve provide after data/props\n callHook(vm, 'created')\n```\n关于 initLifecycle\n vm.$parent = parent\n vm.$root = parent ? parent.$root : vm\n vm.$children = []\n vm.$refs = {}\n vm._watcher = null\n vm._inactive = null\n vm._directInactive = false\n vm._isMounted = false\n vm._isDestroyed = false\n vm._isBeingDestroyed = false\n ```\n\n- initEvents\n```\n vm._events = Object.create(null)\n vm._hasHookEvent = false\n // init parent attached events\n const listeners = vm.$options._parentListeners\n if (listeners) {\n updateComponentListeners(vm, listeners)\n }\n 就是判断父级是否有事件监听,然后给父级进行监听事件\n ```\n- initRender\n```\n vm._vnode = null // the root of the child tree\n vm._staticTrees = null // v-once cached trees\n const options = vm.$options\n const parentVnode = vm.$vnode = options._parentVnode // the placeholder node in parent tree\n const renderContext = parentVnode && parentVnode.context\n vm.$slots = resolveSlots(options._renderChildren, renderContext)\n vm.$scopedSlots = emptyObject\n // 实例绑定 createElement 方法,以便可以正常在内部渲染\n // 参数顺序 tag, data, children, normalizationType, alwaysNormalize\n // 内部使用从模板编译而来的渲染函数\n \n vm._c = (a, b, c, d) => createElement(vm, a, b, c, d, false)\n // 公共版本必须是 normalization 的渲染函数\n vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)\n\n // $attrs & $listeners 应该被监听热更新\n const parentData = parentVnode && parentVnode.data\n\n if (process.env.NODE_ENV !== 'production') {\n defineReactive(vm, '$attrs', parentData && parentData.attrs || emptyObject, () => {\n !isUpdatingChildComponent && warn(`$attrs is readonly.`, vm)\n }, true)\n defineReactive(vm, '$listeners', options._parentListeners || emptyObject, () => {\n !isUpdatingChildComponent && warn(`$listeners is readonly.`, vm)\n }, true)\n } else {\n defineReactive(vm, '$attrs', parentData && parentData.attrs || emptyObject, null, true)\n defineReactive(vm, '$listeners', options._parentListeners || emptyObject, null, true)\n }\n ```\n- callHook(vm, 'beforeCreate') 执行 beforeCreate 函数\n\n- initInjections(vm) 收集注入的依赖\n```\n const result = resolveInject(vm.$options.inject, vm)\n if (result) {\n toggleObserving(false)\n Object.keys(result).forEach(key => {\n if (process.env.NODE_ENV !== 'production') {\n defineReactive(vm, key, result[key], () => {\n warn(\n \t`避免直接改变注入的值,因为将会重新渲染所提供这个值的组件, \n \t改变的值是: \"${key}\",\n vm\n )\n })\n } else {\n defineReactive(vm, key, result[key])\n }\n })\n toggleObserving(true)\n```\n- initState 监听值收集依赖\n```\n vm._watchers = []\n const opts = vm.$options\n if (opts.props) initProps(vm, opts.props) // 赋值 props 数据并收集依赖\n if (opts.methods) initMethods(vm, opts.methods) // 赋值 vue 的各个 method\n if (opts.data) {\n initData(vm) // 收集依赖\n } else {\n observe(vm._data = {}, true /* asRootData */)\n }\n if (opts.computed) initComputed(vm, opts.computed) // 收集依赖\n if (opts.watch && opts.watch !== nativeWatch) {\n initWatch(vm, opts.watch) // 初始化你写的监听对象\n }\n \n```\n- initProvide\n```\n const provide = vm.$options.provide\n if (provide) {\n vm._provided = typeof provide === 'function'\n ? provide.call(vm)\n : provide\n }\n```\n- callHook(vm, 'created') 执行 created 函数\n\n>这就是 _init 中各个函数所做的了。 我们可以看到总结过来就是\n1.初始化了生命状态\n2.进行事件上的监听\n3.渲染视图的初始化;收集所用到的父组件的数据或事件\n4.调用你写的 beforeCreate 方法\n5.initState, 处理了 vue 中的各种数据(props/data/methods.....), 也在这一步针对这些数据进行了依赖收集,数据更新绑定\n6.初始化了 provide 的值, 也可以看出它没有被收集依赖, 是不会影响视图改变的\n7.调用了你写的 created 方法了。\n\n以上,就是你 let app = new Vue() 这一步所发生的所有事情了。\n\n\n那通过平时的使用我们知道,我们是通过调用 $mounted 能把它挂载上页面。所以接下来我们就可以来看看 vue 自己的 $mount 都做了些什么?\n\n答: 就是把 template 或直接写的 render 函数,进行指令、事件等vue 中的语法解析编译成一个 AST 树。通过这个树,通过之前 initRender 中的 $createElement 方法可以生成虚拟DOM, 然后添加到页面中出,不就渲染出来了么。 如果大家使用过 Vue 的 $createElement 方法,相信就知道这个 ast 是怎么一个结构了,拿示例的来说\n```\ncreateElement(\n 'div',\n [\n '先写一些文字',\n createElement('h1', '一则头条'),\n createElement(MyComponent, {\n props: {\n someProp: 'foobar'\n }\n })\n ]\n)\n```\n\n---\n说完了整个过程,现在还比较疑惑的就是它的收集依赖,然后数据改变引起的视图改变到底怎么做呢?\n\n也就是说我们要实现一个模式,vm 可能 data 对象中的一个值,比如 name 改变了,然后就调用重新渲染的函数,这里为了性能,是生成了一个虚拟 Dom, 然后比较哪里改变了进行相应的替换。 \n把这个模式抽象出来,就是我们需要一个 \n\n先说具体实现: 我们视图更新依赖到的值收集起来,这里把每一个依赖到的值称作 dep。每个依赖订阅与它有关的 vue 的 watcher 中心, 这里把 dep 所订阅的 watcher 叫做 sub。 那么 dep 被改变的时候,获取它订阅了那些 watcher, 通知他们进行 update 视图啦。\n\n可以看我画的简图\n![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/417c23088cb0224c6a4464651452c604.png)\n![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/59c0e76f684052df524761ee8f4f6942.png)\n\n这就是依赖对象 和 一个 watcher 对象所涉及到的处理了。\nVue 中又是怎么把一个个的属性,进行操作变成依赖的呢?\n对应它的源码就是 defineReactive 方法。源码如图:\n```\nexport function defineReactive (obj, key, val, customSetter, shallow) {\n const dep = new Dep()\n \n // 迎合预定义的getter / setter\n const getter = property && property.get\n const setter = property && property.set\n if ((!getter || setter) && arguments.length === 2) {\n val = obj[key]\n }\n \n let childOb = !shallow && observe(val)\n Object.defineProperty(obj, key, {\n enumerable: true,\n configurable: true,\n get: function reactiveGetter () {\n const value = getter ? getter.call(obj) : val\n if (Dep.target) {\n dep.depend()\n if (childOb) {\n childOb.dep.depend()\n if (Array.isArray(value)) {\n dependArray(value)\n }\n }\n }\n return value\n },\n set: function reactiveSetter (newVal) {\n const value = getter ? getter.call(obj) : val\n if (newVal === value || (newVal !== newVal && value !== value)) {\n return\n }\n if (setter) {\n setter.call(obj, newVal)\n } else {\n val = newVal\n }\n childOb = !shallow && observe(newVal)\n dep.notify()\n }\n })\n}\n```\n这里就是用的 Object.defineProperty 方法,它可以重写对象的属性的 get 和 set 方法。 当这个属性在 Vue 中被获取的时候,就开始收集依赖,把它收集在这个 vm 的 watcher 中心,并且让它订阅这个 watcher 。当这个属性被重新设置时, 就通知它所订阅的对象去更新。\n\n大致要知道的就是这些了。关于具体是怎么实现把 template 编译成 ast 树, 具体是怎么把事件绑定上去的,你可以尽情的去猜想和推测,或者去看看具体的实现方式。但是 VUE 框架总体来说所做的就是这些事情了, 如果有觉得本文写的不清楚的地方可以提哈 = =\n"}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMTY3LmJ1bmRsZS5qcyIsIm1hcH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YGBcXG7ov5nph4zlsLHmmK/nlKjnmoQgT2JqZWN0LmRlZmluZVByb3BlcnR5IOaWueazle+8jOWug+WPr+S7pemHjeWGmeWvueixoeeahOWxnuaAp+eahCBnZXQg5ZKMIHNldCDmlrnms5XjgIIg5b2T6L+Z5Liq5bGe5oCn5ZyoIFZ1ZSDkuK3ooqvojrflj5bnmoTml7blgJnvvIzlsLHlvIDlp4vmlLbpm4bkvp3otZbvvIzmiorlroPmlLbpm4blnKjov5nkuKogdm0g55qEIHdhdGNoZXIg5Lit5b+D77yM5bm25LiU6K6p5a6D6K6i6ZiF6L+Z5LiqIHdhdGNoZXIg44CC5b2T6L+Z5Liq5bGe5oCn6KKr6YeN5paw6K6+572u5pe277yMIOWwsemAmuefpeWug+aJgOiuoumYheeahOWvueixoeWOu+abtOaWsOOAglxcblxcbuWkp+iHtOimgeefpemBk+eahOWwseaYr+i/meS6m+S6huOAguWFs+S6juWFt+S9k+aYr+aAjuS5iOWunueOsOaKiiB0ZW1wbGF0ZSAg57yW6K+R5oiQIGFzdCDmoJHvvIwg5YW35L2T5piv5oCO5LmI5oqK5LqL5Lu257uR5a6a5LiK5Y6755qE77yM5L2g5Y+v5Lul5bC95oOF55qE5Y6754yc5oOz5ZKM5o6o5rWL77yM5oiW6ICF5Y6755yL55yL5YW35L2T55qE5a6e546w5pa55byP44CC5L2G5pivIFZVRSDmoYbmnrbmgLvkvZPmnaXor7TmiYDlgZrnmoTlsLHmmK/ov5nkupvkuovmg4XkuoYsIOWmguaenOacieinieW+l+acrOaWh+WGmeeahOS4jea4healmueahOWcsOaWueWPr+S7peaPkOWTiCA9ID1cXG5cIjsiXSwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/188.bundle.js b/188.bundle.js new file mode 100644 index 0000000..2a5cf7c --- /dev/null +++ b/188.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkreact_wyz=self.webpackChunkreact_wyz||[]).push([[188],{188:(n,e,r)=>{r.r(e),r.d(e,{default:()=>t});const t="## learn typescript\n### 类型\n基本类型: \n```\nstring number bool \n```\n\n数组 `[]`: \n```\nstring[] number[]\n```\n\n元祖: \n```\n[string, number]. 数组中有不同的数据类型\n```\n\n对象:\n```\n{ name: string; age: number }\n```\n\n函数:\n```\n(arg1: string, arg?: bool) => void\n```\n\nSymbol: \n```\nlet symbol = Symbol(\"key\"); \n```\n\n空:\n```\nundefined null\n```\n\n任何类型: \n```\nany\n```\n\n不存在的值: \n```\nnever\n```\n\n### 如何定义类型\n`type` 定义类型变量\n```\ntype Person = { name: string; age: number}\nts 使用 const person1:Person = { name: '22', age: 1};\n```\n\n`Interfaces` 声明 `对象` 类型的一种方法\n```\nInterface Person { name: string; age: number}\n```\n\n`extends` 类型继承于声明的类型\n```\ninterface a { name: string}\ninterface b extends a {\n\tage: number\n}\nb 的类型等于 { name: string; age: number }\n```\n\nin 判断属性是哪个类型中的\n```\ntype PersonListQuery = { user_ids: string[] }\ntype DogListQuery = { dog_ids: string[] }\n\nfunction getList(query: PersonListQuery | DogListQuery ) {\n\tif ('user_ids' in PersonListQuery) {\n\t \t// 这里可以推导出 query 类型是 PersonListQuery\n\t}\n}\n\n```\n\n\n### 类型组合\n\n`Required` 将 T 中所有属性变成必选\n```\nRequired<{ a?: bool} > = { a: bool }\n```\n\n`Partial` 将 T 中所有属性变成可选\n```\nPartial<{ a: bool }> = { a?: bool }\n```\n\n`Readonly` 将 T 中所有属性变成只读,后续 ts 会检测该类型不允许修改\n```\nconst person2: Readonly<{name: string}> = {name: '22'}\nperson2.name = '33' //error\n```\n`Omit` 删除某些属性\n```\ninterface Person {\n name: string;\n age: number;\n}\n \ntype Name = Omit;\nName 的类型定义为 { name: string }\n```\n\n`Pick` 选择类型中的某些属性\n```\ninterface Person {\n name: string;\n age: number;\n}\ntype Name = Pick;\nName 的类型定义为 { name: string }\n```\n\n\n`Exclude` 删除类型 T 中 deleteT 的类型, 相当于 Omit, 第二个值可以是 keys ,也可以是一个类型变量\n```\ninterface Person {\n name: string;\n age: number;\n}\ntype Age = { age: number }\ntype Name = Exclude\nName 的类型定义为 { name: string }\n```\n\n\n`Extract` 提取 T 继承于的 U 类型\n```\ntype Person = { name: string ; age: number } \ntype PersonDetail = { pet: any; phone: number } \ntype Name = { name: string }\ntype Name = Extract\n 将提取出含有 name 的类型 Person\n```\n\n\n`Parameters` 获取函数类型的函数类型\n```\ntype getName = (perpson: Person) => string;\ntype queryType = Parameters;\nqueryType 的类型定义为 Person\n```\n\n`ReturnType` 获取函数类型的返回值类型\n```\ntype getName = (perpson: Person) => string;\ntype resType = ReturnType;\nvalueType 类型为 string\n```\n\n`Awaited` 获取异步返回的值类型\n```\ntype getPerson = (id: string) => Promise\ntype resType = ReturnType // Promise\ntype valueType = Awaited // Person\n```\n\n`Record` 定义对象的 key 键类型\n```\ntype Keys = 'name' | 'age' \ntype person = Record\n// person 的属性只能为 name 和 age\n```\n\n`NonNullable` 去除类型中定义的 null 和 undefined \n```\ntype PersonHobby = hobby: string | undefined;\ntype Hobby = NonNullable\nHobby 类型为 string\n```\n\n### 类型操作\n\n`typeof Object` 获得`对象`的类型\n```\nconst person1 = { name: '22', age: 1}\ntype Person = typeof person1\nPerson 类型为 { name: string; age: number }\n```\n\n`keyof T` 获得类型中的属性\n```\ntype Person = { name: string; age: number }\ntype Key = keyof Person \nkey 的类型为 'name' | 'age'\n```\n通常我们可以通过 keyof 约束对象的传参, 如\n```\ntype Person = { name: string; age: number }\ntype Key = keyof Person;\ntype getPersonAtrribute = (person: Person, key: Key) => Person[Key];\n```\n或者某些情况下我们想知道一个对象的属性值 \n```\nconst workPerson = { \n\t'1': { name: '1', age: 1},\n\t'2': { name: '2', age: 2},\n}\ntype WorkPerson = typeof workPerson; // { '1': {name: string; age: number }, '2': {name: string; age: number }\ntype Key = keyof WorkPerson // '1' | '2'\ntype Person = WorkPerson[Key] // {name: string; age: number }\n```\n `|` 类型兼容\n```\ntype width = 'string' | 'number';\n\n则 width 可以是 '32px' 也可以是 '32' 在 渲染时兼容两种类型\n```\n\n\n### 函数重载\n\n定义不同类型的输入,推到出不同类型的输出\n\n```\ntype PersonListQuery = { user_ids: string[] };\ntype DongListQuery = { dog_ids: string[] };\nfunction getList(request: PersonListQuery): Person[];\nfunction getList(request: DogListQuery): Dog[];\n\nfunction getList(query: PersonListQuery | DogListQuery) {\n if ('user_ids' in query) { \n return [] as Person[];\n } else {\n return [] as Dog[];\n }\n}\n\nconst a = getList({ personIds: [], region: 'us'})\n此时 a 的类型将能推到出是 Person[]\n```\n\n### 泛型\n类型的传参。 用 T 标识,在实际运用时你传入什么类型,该类型就作为后续推导。\n```\nasync function request(url: string): Promise {\n const res = await fetch(url)\n return res.json();\n}\n\nconst res = await request('getPersonInfo?id=1'); \n此时 ts 可以推导出 res 的类型是 Person\n```\n\n### Infer 类型参数使用\n通过 Infer 一个类型为变量,定义出获取类型的方法\n```\ntype addResultType = T extends { a: infer U, b: infer U } ? U : never;\ntype numberAdd = addResultType<{ a: 1, b: 2 }> // 推到出结果类型为 number\ntype textAdd = addResultType<{ a: 'hello', b: 'world' }> // 推到出结果类型为 string\n```\n\n\n### 枚举 enum\n变量的值是约定的几个取值\n\n```\nconst enum PageType {\n HOME = 'home',\n VIDEO = 'video',\n}\n\nfunction getPageUrl(page: PageType) {\n return {\n [PageType.VIDEO]: \"/video\",\n [PageType.HOME]: \"/home\",\n }[page];\n}\n```\n\n\n## tsconfig\n了解了 ts 对于类型的定义和各种规则后,我们则可以在编写 js 代码时利用并进行类型约束。于此同时,我们需要引入 typescript 库去获得这些 ts 能力。\n\n### 如何引入\n```\nnpm install typescript \n// 不必再多说\n```\n\n### 命令\ntypescript 包是有命令文件的,通常 ts 的运行则是通过 tsc 配合相关命令去执行的. 具体命令大家可以安装包之后通过 tsc -h 查看\n![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/349ffc362f0d831a780d2d7f754893a1.png)\n\n### 配置 [官网](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)\n如果你看了 tsc 命令,你会发现它是有很多命令的,并且有的命令还伴随这相关参数。在工作文件夹中,我们则通过配置文件 `tsconfig.js ` 去配置,保证在项目中的运用。 配置参数这里就不细讲了,还是看官方文档靠谱点。\n"}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMTg4LmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoia0lBQUEsdW1MIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vcmVhY3Rfd3l6Ly4uLy4uL2Jsb2dzL21hcmtkb3duL3R5cGVzY3JpcHQubWQiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgXCIjIyBsZWFybiB0eXBlc2NyaXB0XFxuIyMjIOexu+Wei1xcbuWfuuacrOexu+WeizogXFxuYGBgXFxuc3RyaW5nIG51bWJlciBib29sIFxcbmBgYFxcblxcbuaVsOe7hCBgW11gOiAgXFxuYGBgXFxuc3RyaW5nW10gIG51bWJlcltdXFxuYGBgXFxuXFxu5YWD56WWOiAgXFxuYGBgXFxuW3N0cmluZywgbnVtYmVyXS4g5pWw57uE5Lit5pyJ5LiN5ZCM55qE5pWw5o2u57G75Z6LXFxuYGBgXFxuXFxu5a+56LGhOlxcbmBgYFxcbnsgbmFtZTogc3RyaW5nOyBhZ2U6IG51bWJlciB9XFxuYGBgXFxuXFxu5Ye95pWw77yaXFxuYGBgXFxuKGFyZzE6IHN0cmluZywgYXJnPzogYm9vbCkgPT4gdm9pZFxcbmBgYFxcblxcblN5bWJvbDogIFxcbmBgYFxcbmxldCBzeW1ib2wgPSBTeW1ib2woXFxcImtleVxcXCIpOyBcXG5gYGBcXG5cXG7nqbrvvJpcXG5gYGBcXG51bmRlZmluZWQgICBudWxsXFxuYGBgXFxuXFxu5Lu75L2V57G75Z6L77yaIFxcbmBgYFxcbmFueVxcbmBgYFxcblxcbuS4jeWtmOWcqOeahOWAvO+8miBcXG5gYGBcXG5uZ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7pgJrov4cgdHNjIC1oIOafpeeci1xcbiFb5Zyo6L+Z6YeM5o+S5YWl5Zu+54mH5o+P6L+wXShodHRwczovL2ktYmxvZy5jc2RuaW1nLmNuL2Jsb2dfbWlncmF0ZS8zNDlmZmMzNjJmMGQ4MzFhNzgwZDJkN2Y3NTQ4OTNhMS5wbmcpXFxuXFxuIyMjIOmFjee9riBb5a6Y572RXShodHRwczovL3d3dy50eXBlc2NyaXB0bGFuZy5vcmcvZG9jcy9oYW5kYm9vay90c2NvbmZpZy1qc29uLmh0bWwpXFxu5aaC5p6c5L2g55yL5LqGIHRzYyDlkb3ku6TvvIzkvaDkvJrlj5HnjrDlroPmmK/mnInlvojlpJrlkb3ku6TnmoTvvIzlubbkuJTmnInnmoTlkb3ku6Tov5jkvLTpmo/ov5nnm7jlhbPlj4LmlbDjgILlnKjlt6XkvZzmlofku7blpLnkuK3vvIzmiJHku6zliJnpgJrov4fphY3nva7mlofku7YgYHRzY29uZmlnLmpzIGAg5Y676YWN572u77yM5L+d6K+B5Zyo6aG555uu5Lit55qE6L+Q55So44CCIOmFjee9ruWPguaVsOi/memHjOWwseS4jee7huiusuS6hu+8jOi/mOaYr+eci+WumOaWueaWh+aho+mdoOiwseeCueOAglxcblwiOyJdLCJuYW1lcyI6W10sInNvdXJjZVJvb3QiOiIifQ== \ No newline at end of file diff --git a/27.bundle.js b/27.bundle.js new file mode 100644 index 0000000..32add2f --- /dev/null +++ b/27.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkcboy_blog=self.webpackChunkcboy_blog||[]).push([[27],{27:function(e,o,p){p.r(o),p.d(o,{default:function(){return a}});var c=p(358);const t={class:"component-webpack"},s={};var a=(0,p(389).A)(s,[["render",function(e,o){return(0,c.uX)(),(0,c.CE)("div",t,o[0]||(o[0]=[(0,c.Fv)('

一 webpack 是什么?

它是一个打包工具。 噗,完啦?

来,我们看官方概念: webpack 是一个现代 JavaScript 应用程序的静态模块打包工具。当 webpack 处理应用程序时,它会在内部构建一个 依赖图(dependency graph),此依赖图会映射项目所需的每个模块,并生成一个或多个 bundle。

内部如何构建一个依赖图,我们知道 webpack 会配置一个入口,这就是从这入口文件开始, 找到所有被依赖到的文件,比如其他 js / image / json 文件等,然后通过 loader 对这些文件进行处理、编译、打包、优化,生成一个 bundle 或者多个 bundle。

它的原理

通过以上,主要就是找依赖, 通过配置处理相应环境,根据你的需要配置插件进行优化(如 profill、babel、 miniSize etc) 打包出文件,可以放到服务器上运行。

关于找依赖,可以想到关于模块化的语法: import 、require、@import etc, 通过解析对应的语法寻找相应的依赖。然后通过读取依赖到的文件,根据对应的 loader 进行处理文件,最后根据你的插件配置,分割,压缩或注入等,根据 output config输出到对应的文件夹。

这里推荐一篇 webpack原理 文章, 下面就提一提我最近遇到的一个很神奇的问题吧

关于 tree shaking

想象抖一抖树,枯萎的叶子就会脱落。 这里指的是把没有用到的代码删除掉,从而减小文件的大小。通过这一优化,在引用多个第三方库时,能够大大的减少你的文件大小,但请确定这个包是没有副作用的。

什么是副作用? 就是在导入时会自行运行一段函数,从而改变了 window 变量啊或者其他的变量以供导入的包能正常运行, 而不是只单单 export 了变量。

它是依赖于 es2015 的 静态导入导出( import / export)。在打包时就会通过 import 确定引用包的 export 导出的某一个变量之一, 在告知没有副作用的情况下,删除掉没有用到的其他的导出代码。

静态导入是指一开始就默认加载这个文件,而不是一步一步执行代码判断逻辑,去导入对应文件

webpack 在生成环境下,默认打开树抖动配置, 如下配置。

optimization: {\n\tprovidedExports: true,\n\tusedExports: true,\n\tsideEffects: true,\n\tconcatenateModules: true,\n }\n

providedExports 开启 export 导出收集; usedExportts 告诉webpack确定每个模块的已使用导出; concatenateModules 告诉webpack查找模块图的各个部分,这些部分可以安全地连接成一个模块; sideEffects 告诉webpack识别 sideEffects 标志的 package.json 或规则以跳过模块,这些模块在未使用导出时被标记为不包含副作用, 则可以把无副作用的未使用的导出进行删除。

所以如果你的包无副作用,推荐在 package.json 设置 sideEffects: false 开启树抖动。 注意, 它会删掉样式文件,因为样式文件是没有 export 的。所以我们需要声明样式文件是有副作用的。 在 package.json 中设置:

sideEffects: [\n\t'*.css'\n]\n

总结,为了利用树木摇晃,你必须: 1 使用ES2015模块语法 (配置 babel 禁止转义 es6 模块语义) 2 将"sideEffects"属性添加到项目的 package.json文件中。 3 配合压缩工具一起使用

demo 通过配置 webpack.prod.js sideEffects 值, 你可以看到 build 时 main.js 文件的大小发生改变。

',20)]))}]])}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMjcuYnVuZGxlLmpzIiwibWFwcGluZ3MiOiIyS0FBZUEsTUFBTSxxQkNDZkMsRUFBUyxDQUFDLEVBS2hCLE9BRmlDLEUsT0FBQSxHQUFnQkEsRUFBUSxDQUFDLENBQUMsUyxnQ0RKakRDLEVBQUFBLEVBQUFBLElBNkNKLE1BN0NJQyxFQTZDSkMsRUFBQSxLQUFBQSxFQUFBLEtBN0NOQyxFQUFBQSxFQUFBQSxJQUFBLGlxRSIsInNvdXJjZXMiOlsid2VicGFjazovL2Nib3ktYmxvZy8uLi8uLi9ibG9ncy9tYXJrZG93bi93ZWJwYWNrLm1kIiwid2VicGFjazovL2Nib3ktYmxvZy8uLi8uLi9ibG9ncy9tYXJrZG93bi93ZWJwYWNrLm1kPzZiN2YiXSwic291cmNlc0NvbnRlbnQiOlsiPHRlbXBsYXRlPjxkaXYgY2xhc3M9XCJjb21wb25lbnQtd2VicGFja1wiPjxoND7kuIAgIHdlYnBhY2sg5piv5LuA5LmI77yfPC9oND5cbjxwPuWug+aYr+S4gOS4quaJk+WMheW3peWFt+OAgiDlmZfvvIzlrozllabvvJ88L3A+XG48cD7mnaXvvIzmiJHku6znnIvlrpjmlrnmpoLlv7U6ICB3ZWJwYWNrIOaYr+S4gOS4queOsOS7oyBKYXZhU2NyaXB0IOW6lOeUqOeoi+W6j+eahOmdmeaAgeaooeWdl+aJk+WMheW3peWFt+OAguW9kyB3ZWJwYWNrIOW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Rj77yMIOmAmui/h+ino+aekOWvueW6lOeahOivreazleWvu+aJvuebuOW6lOeahOS+nei1luOAgueEtuWQjumAmui/h+ivu+WPluS+nei1luWIsOeahOaWh+S7tu+8jOagueaNruWvueW6lOeahCBsb2FkZXIg6L+b6KGM5aSE55CG5paH5Lu277yM5pyA5ZCO5qC55o2u5L2g55qE5o+S5Lu26YWN572u77yM5YiG5Ymy77yM5Y6L57yp5oiW5rOo5YWl562J77yM5qC55o2uIG91dHB1dCBjb25maWfovpPlh7rliLDlr7nlupTnmoTmlofku7blpLnjgII8L3A+XG48cD7ov5nph4zmjqjojZDkuIDnr4cgPGEgaHJlZj1cImh0dHBzOi8vanVlamluLmltL2VudHJ5LzViMGUzZWJhNTE4ODI1MTUzNDM3OTYxNVwiPndlYnBhY2vljp/nkIY8L2E+IOaWh+eroCwg5LiL6Z2i5bCx5o+Q5LiA5o+Q5oiR5pyA6L+R6YGH5Yiw55qE5LiA5Liq5b6I56We5aWH55qE6Zeu6aKY5ZCnPC9wPlxuPGg0PuWFs+S6jiA8YSBocmVmPVwiaHR0cHM6Ly93ZWJwYWNrLmRvY3NjaGluYS5vcmcvZ3VpZGVzL3RyZWUtc2hha2luZy9cIj50cmVlIHNoYWtpbmc8L2E+PC9oND5cbjxwPuaDs+ixoeaKluS4gOaKluagke+8jOaer+iQjueahOWPtuWtkOWwseS8muiEseiQveOAgiDov5nph4zmjIfnmoTmmK/miormsqHmnInnlKjliLDnmoTku6PnoIHliKDpmaTmjonvvIzku47ogIzlh4/lsI/mlofku7bnmoTlpKflsI/jgILpgJrov4fov5nkuIDkvJjljJbvvIzlnKjlvJXnlKjlpJrkuKrnrKzkuInmlrnlupPml7bvvIzog73lpJ/lpKflpKfnmoTlh4/lsJHkvaDnmoTmlofku7blpKflsI/vvIzkvYbor7fnoa7lrprov5nkuKrljIXmmK/msqHmnInlia/kvZznlKjnmoTjgII8L3A+XG48YmxvY2txdW90ZT5cbjxwPuS7gOS5iOaYr+WJr+S9nOeUq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ZWJwYWNrQDUuOTQuMF93ZWJwYWNrLV9mdXFrd2dncGxoZXkzb2l2dHdlMnN0ZG82ZS9ub2RlX21vZHVsZXMvdnVlLWxvYWRlci9kaXN0L2V4cG9ydEhlbHBlci5qc1wiXG5jb25zdCBfX2V4cG9ydHNfXyA9IC8qI19fUFVSRV9fKi9leHBvcnRDb21wb25lbnQoc2NyaXB0LCBbWydyZW5kZXInLHJlbmRlcl1dKVxuXG5leHBvcnQgZGVmYXVsdCBfX2V4cG9ydHNfXyJdLCJuYW1lcyI6WyJjbGFzcyIsInNjcmlwdCIsIl9jcmVhdGVFbGVtZW50QmxvY2siLCJfaG9pc3RlZF8xIiwiX2NhY2hlIiwiX2NyZWF0ZVN0YXRpY1ZOb2RlIl0sInNvdXJjZVJvb3QiOiIifQ== \ No newline at end of file diff --git a/272.bundle.js b/272.bundle.js new file mode 100644 index 0000000..e59406c --- /dev/null +++ b/272.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkreact_wyz=self.webpackChunkreact_wyz||[]).push([[272],{272:(n,e,s)=>{s.r(e),s.d(e,{default:()=>t});const t='### canvas\n\ncanvas 是 HTML 5 新出的图片元素,它是 2d 绘图 API, 使用 JavaScript 调用API 可以画 lines, shapes, images, text 甚至其他你想话的, 并且不需要什么插件。\n\n它是作为一个画布存在在网页中, 画布上有你绘制的图案,利用 js 你可以实时的改变画布上的图案,以实现动画。\n\n它的支持性也挺好,IE 9 开始支持,Chrome和Opera 9+ 也支持。\n\n### svg\n\nSVG 可缩放矢量图形, 是 XML 用来描述二维图形和绘图程序的语言。目前SVG在Firefox、Opera、Webkit浏览器、IE等浏览器中已经部分实现。\n\n> 什么是 XML \n> 它是一种类似于 HTML 的标记语言,设计宗旨在于传输数据而不是显示数据。\n> XML 数据以纯文本格式进行存储,因此提供了一种独立于软件和硬件的数据存储方法。通过读取你可以获取存储于其中的数据\n\n\nSVG可以通过定义必要的线和形状来创建一个图形,也可以修改已有的位图,或者将这两种方式结合起来创建图形。图形和其组成部分可以变形,可以合成,还可以通过滤镜完全改变外观。\n\nSVG提供了一些元素,用于定义圆形、矩形、简单或复杂的曲线,以及其他形状。\n一个简单的SVG文档由 `` 根元素和基本的形状元素构成。另外还有一个g元素,它用来把若干个基本形状编成一个组。\n\neg:\n```\n\n\n \n\n \n\n SVG\n\n\n\n```\n\n可以看到 svg 是在内部组合各种元素绘制形成相应的图案。 并且矢量顾名思义是可以自由缩放的,根据屏幕像素点进行缩放,保留了图案的高清晰度。\n\n### 总结\n通过以上,我们可以知道 svg 和 canvas 的相同点,它们都是可以绘图的元素,并有自身的用法。\ncanvas 是一块画布,纯用 js 去画画的。根据你的 js 编写,动态去渲染画布上的图案,适用一些大量数据交互修改的,比较复杂的动画。由于它仅仅是根据你设定的大小,它是依赖于分辨率的。\n 而 svg 是一个个元素组成在一起的, 包含 animate 元素,可做一些小小的动画, 它的矢量优点也更适合做一些高保真的静态图片。'}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMjcyLmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoia0lBQUEscXdDIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vcmVhY3Rfd3l6Ly4uLy4uL2Jsb2dzL21hcmtkb3duL2NhbnZhcy1zdmcubWQiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgXCIjIyMgIGNhbnZhc1xcblxcbmNhbnZhcyDmmK8gSFRNTCA1IOaWsOWHuueahOWbvueJh+WFg+e0oO+8jOWug+aYryAyZCDnu5jlm74gQVBJ77yMIOS9v+eUqCBKYXZhU2NyaXB0ICDosIPnlKhBUEkg5Y+v5Lul55S7ICBsaW5lcywgc2hhcGVzLCBpbWFnZXMsIHRleHQg55Sa6Iez5YW25LuW5L2g5oOz6K+d55qE77yMIOW5tuS4lOS4jemcgOimgeS7gOS5iOaPkuS7tuOAglxcblxcbuWug+aYr+S9nOS4uuS4gOS4queUu+W4g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jlgZrkuIDkupvpq5jkv53nnJ/nmoTpnZnmgIHlm77niYfjgIJcIjsiXSwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/280.bundle.js b/280.bundle.js new file mode 100644 index 0000000..3a0f4fc --- /dev/null +++ b/280.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkreact_wyz=self.webpackChunkreact_wyz||[]).push([[280],{280:(n,t,o)=>{o.r(t),o.d(t,{default:()=>i});const i="作为一个程序员,工作到现在,也将近半年了。公司对员工的代码提交也会有 review 流程。代码的 review 来讲,一般就是看格式、命名、逻辑是否有错,代码是否还有可以抽象的地方,这里总结一下自己遇到的代码规范方面的问题,大家一起写规范的代码,做一个看上去专业码农吧。\n***\n#### **js规范**\n- 代码的缩进了,一般是两格或四格,我司采用的是四格,这里可以根据自己喜好和公司要求了。\n\n- 中英文之间有空格间隔,像这样: `我专业引用 English 单词`\n\n- 命名规范,命名的驼峰式不用再说了。这里具体情况具体分析一下\n - 变量的命名:小驼峰式\n - 函数的命名:小驼峰式\n - 常量:全部大写\n - 构造函数: 大驼峰式\n - 类的成员: 公共属性和方法就是小驼峰式, 私有属性和方法加上`-`前缀,然后是小驼峰式,如 `_nameFrist\n \n ---\n \n#### **css规范**\n- css 的基本命名, 自己刚写的时候以为也是写小驼峰式,后来就呵呵了。css 当中就是用 `-` 连接了, 如 `search-button`,在定义 id 的时候是用小驼峰了。\n\n- css 名字意思定义。这里有一个 BEM 的命名法则参考,可以看看我之前写的一篇博客[了解BEM](http://blog.csdn.net/dadadeganhuo/article/details/76600264)\n- css 命名的统一前缀, 在一个项目中,约定好同一个前缀,可避免样式的覆盖。\n\n- css 样式书写顺序:\n\t- 显示属性:display/list-style/position/float/clear …\n\t- 自身属性(盒模型):width/height/margin/padding/border\n\t- 背景:background\n\t- 行高:line-height\n\t- 文本属性:color/font/text-decoration/text-align/...\n\t- 其他:cursor/z-index/zoom/overflow\n\t- CSS3属性:transform/transition/animation/box-shadow/border-radius\n\t- 如果使用CSS3的属性,如果有必要加入浏览器前缀,则按照 -webkit- / -moz- / -ms- / -o- /\nstd的顺序进行添加,标准属性写在最后。\n\t- 链接的样式请严格按照如下顺序添加: a:link -> a:visited -> a:hover -> a:active\n\n- 代码优化,能合并的属性就合并写,没用的属性也删掉,避免重复样式,避免使用 `!important`\n\n---\n\n#### **git commit log 规则**\n\n- 首先就是commit 内容的分类了,如图片所示:\n![这里写图片描述](https://img-blog.csdn.net/20170830144139403?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFkYWRlZ2FuaHVv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)定好分类,分类后面可以加你本次修改具体文件,然后组织本次修改的内容,就写好了 commit log啦。比如:`feat(login): 新增登录验证功能`,这表达出了你再login文件上新增了一个验证的功能。编写正确的 log 信息,能够清楚的表述你写的代码目的。\n\n- commit 次数,这里我们每完成一个小点的时候,都可以 commit 一下,因为commit 是记录你完成一个项目的具体过程。\n\n---\n= = 之前没好好总结,今天写总结的时候,也去搜了搜别的文章,发现这样的文章其实挺多,自己以前都没怎么好好看看 = = 。\n欢迎补充啊~\n\n#### 参考 \n> [前端人员必看的CSS规范](https://www.douban.com/note/499976405/?type=like)\n> [Commit message 和 Change log 编写指南](http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html)\n"}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMjgwLmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoia0lBQUEsazZEIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vcmVhY3Rfd3l6Ly4uLy4uL2Jsb2dzL21hcmtkb3duL2NvZGUtZm9ybWF0Lm1kIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IFwi5L2c5Li65LiA5Liq56iL5bqP5ZGY77yM5bel5L2c5Yiw546w5Zyo77yM5Lmf5bCG6L+R5Y2K5bm05LqG44CC5YWs5Y+45a+55ZGY5bel55qE5Luj56CB5o+Q5Lqk5Lmf5Lya5pyJIHJldmlldyDmtYHnqIvjgILku6PnoIHnmoQgcmV2aWV3IOadpeiusu+8jOS4gOiIrOWwseaYr+eci+agvOW8j+OAgeWRveWQjeOAgemAu+i+keaYr+WQpuaciemUme+8jOS7o+eggeaYr+WQpui/mOacieWPr+S7peaKveixoeeahOWcsOaWue+8jOi/memHjOaAu+e7k+S4gOS4i+iHquW3semBh+WIsOeahOS7o+eggeinhOiMg+aWuemdoueahOmXrumimO+8jOWkp+WutuS4gOi1t+WGmeinhOiMg+eahOS7o+egge+8jOWBmuS4gOS4queci+S4iuWOu+S4k+S4mueggeWGnOWQp+OAglxcbioqKlxcbiMjIyMgKipqc+inhOiMgyoqXFxuLSDku6PnoIHnmoTnvKnov5vkuobvvIzkuIDoiKzmmK/kuKTmoLzmiJblm5vmoLzvvIzmiJHlj7jph4fnlKjnmoTmmK/lm5vmoLzvvIzov5nph4zlj6/ku6XmoLnmja7oh6rlt7Hllpzlpb3lkozlhazlj7jopoHmsYLkuobjgIJcXG5cXG4tIOS4reiLseaWh+S5i+mXtOacieepuuagvOmXtOmalO+8jOWDj+i/meagtzogYOaIkeS4k+S4muW8leeUqCBFbmdsaXNoIOWNleivjWBcXG5cXG4tIOWRveWQjeinhOiMg++8jOWRveWQjeeahOmpvOWzsOW8j+S4jeeUqOWGjeivtOS6huOAgui/memHjOWFt+S9k+aDheWGteWFt+S9k+WIhuaekOS4gOS4i1xcbiAgIC0g5Y+Y6YeP55qE5ZG95ZCN77ya5bCP6am85bOw5byPXFxuICAgLSDlh73mlbDnmoTlkb3lkI3vvJrlsI/pqbzls7DlvI9cXG4gICAtIOW4uOmHj++8muWFqOmDqOWkp+WGmVxcbiAgIC0g5p6E6YCg5Ye95pWw77yaIOWkp+mpvOWzsOW8j1xcbiAgIC0g57G755qE5oiQ5ZGY77yaIOWFrOWFseWxnuaAp+WSjOaW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MgXFxuPiBb5YmN56uv5Lq65ZGY5b+F55yL55qEQ1NT6KeE6IyDXShodHRwczovL3d3dy5kb3ViYW4uY29tL25vdGUvNDk5OTc2NDA1Lz90eXBlPWxpa2UpXFxuPiBbQ29tbWl0IG1lc3NhZ2Ug5ZKMIENoYW5nZSBsb2cg57yW5YaZ5oyH5Y2XXShodHRwOi8vd3d3LnJ1YW55aWZlbmcuY29tL2Jsb2cvMjAxNi8wMS9jb21taXRfbWVzc2FnZV9jaGFuZ2VfbG9nLmh0bWwpXFxuXCI7Il0sIm5hbWVzIjpbXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/344.bundle.js b/344.bundle.js new file mode 100644 index 0000000..782c780 --- /dev/null +++ b/344.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkreact_wyz=self.webpackChunkreact_wyz||[]).push([[344],{344:(e,n,t)=>{t.r(n),t.d(n,{default:()=>s});const s="#### 一 webpack 是什么?\n它是一个打包工具。 噗,完啦?\n\n来,我们看官方概念: webpack 是一个现代 JavaScript 应用程序的静态模块打包工具。当 webpack 处理应用程序时,它会在内部构建一个 依赖图(dependency graph),此依赖图会映射项目所需的每个模块,并生成一个或多个 bundle。\n\n内部如何构建一个依赖图,我们知道 webpack 会配置一个入口,这就是从这入口文件开始, 找到所有被依赖到的文件,比如其他 js / image / json 文件等,然后通过 loader 对这些文件进行处理、编译、打包、优化,生成一个 bundle 或者多个 bundle。\n\n#### 它的原理\n通过以上,主要就是找依赖, 通过配置处理相应环境,根据你的需要配置插件进行优化(如 profill、babel、 miniSize etc) 打包出文件,可以放到服务器上运行。 \n\n关于找依赖,可以想到关于模块化的语法: import 、require、@import etc, 通过解析对应的语法寻找相应的依赖。然后通过读取依赖到的文件,根据对应的 loader 进行处理文件,最后根据你的插件配置,分割,压缩或注入等,根据 output config输出到对应的文件夹。\n\n这里推荐一篇 [webpack原理](https://juejin.im/entry/5b0e3eba5188251534379615) 文章, 下面就提一提我最近遇到的一个很神奇的问题吧\n\n#### 关于 [tree shaking](https://webpack.docschina.org/guides/tree-shaking/)\n想象抖一抖树,枯萎的叶子就会脱落。 这里指的是把没有用到的代码删除掉,从而减小文件的大小。通过这一优化,在引用多个第三方库时,能够大大的减少你的文件大小,但请确定这个包是没有副作用的。\n>什么是副作用?\n就是在导入时会自行运行一段函数,从而改变了 window 变量啊或者其他的变量以供导入的包能正常运行, 而不是只单单 export 了变量。\n\n它是依赖于 es2015 的 `静态导入导出( import / export)`。在打包时就会通过 import 确定引用包的 export 导出的某一个变量之一, 在告知没有副作用的情况下,删除掉没有用到的其他的导出代码。 \n> 静态导入是指一开始就默认加载这个文件,而不是一步一步执行代码判断逻辑,去导入对应文件\n\nwebpack 在生成环境下,默认打开树抖动配置, 如下配置。\n```\noptimization: {\n\tprovidedExports: true,\n\tusedExports: true,\n\tsideEffects: true,\n\tconcatenateModules: true,\n }\n ```\n \n `providedExports` 开启 export 导出收集;\n` usedExportts` 告诉webpack确定每个模块的已使用导出;\n` concatenateModules` 告诉webpack查找模块图的各个部分,这些部分可以安全地连接成一个模块;\n`sideEffects` 告诉webpack识别 sideEffects 标志的 package.json 或规则以跳过模块,这些模块在未使用导出时被标记为不包含副作用, 则可以把无副作用的未使用的导出进行删除。\n\n所以如果你的包无副作用,推荐在 package.json 设置 `sideEffects: false` 开启树抖动。\n注意, 它会删掉样式文件,因为样式文件是没有 export 的。所以我们需要声明样式文件是有副作用的。\n在 package.json 中设置:\n```\nsideEffects: [\n\t'*.css'\n]\n```\n>总结,为了利用树木摇晃,你必须:\n> 1 使用ES2015模块语法 (配置 babel 禁止转义 es6 模块语义)\n> 2 将\"sideEffects\"属性添加到项目的 package.json文件中。\n> 3 配合压缩工具一起使用\n\n\n[demo](https://github.com/cleverboy32/tree-shaking-css)\n通过配置 `webpack.prod.js` sideEffects 值, 你可以看到 build 时 main.js 文件的大小发生改变。"}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWx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OW8gOWQr+agkeaKluWKqOOAglxcbuazqOaEjywg5a6D5Lya5Yig5o6J5qC35byP5paH5Lu277yM5Zug5Li65qC35byP5paH5Lu25piv5rKh5pyJIGV4cG9ydCDnmoTjgILmiYDku6XmiJHku6zpnIDopoHlo7DmmI7moLflvI/mlofku7bmmK/mnInlia/kvZznlKjnmoTjgIJcXG7lnKggcGFja2FnZS5qc29uIOS4reiuvue9ru+8mlxcbmBgYFxcbnNpZGVFZmZlY3RzOiBbXFxuXFx0JyouY3NzJ1xcbl1cXG5gYGBcXG4+5oC757uT77yM5Li65LqG5Yip55So5qCR5pyo5pGH5pmD77yM5L2g5b+F6aG777yaXFxuPiAxIOS9v+eUqEVTMjAxNeaooeWdl+ivreazlSAo6YWN572uIGJhYmVsIOemgeatoui9rOS5iSBlczYg5qih5Z2X6K+t5LmJ77yJXFxuPiAyIOWwhlxcXCJzaWRlRWZmZWN0c1xcXCLlsZ7mgKfmt7vliqDliLDpobnnm67nmoQgcGFja2FnZS5qc29u5paH5Lu25Lit44CCXFxuPiAgMyDphY3lkIjljovnvKnlt6XlhbfkuIDotbfkvb/nlKhcXG5cXG5cXG5bZGVtb10oaHR0cHM6Ly9naXRodWIuY29tL2NsZXZlcmJveTMyL3RyZWUtc2hha2luZy1jc3MpXFxu6YCa6L+H6YWN572uICBgd2VicGFjay5wcm9kLmpzYCBzaWRlRWZmZWN0cyDlgLzvvIwg5L2g5Y+v5Lul55yL5YiwIGJ1aWxkIOaXtiBtYWluLmpzIOaWh+S7tueahOWkp+Wwj+WPkeeUn+aUueWPmOOAglwiOyJdLCJuYW1lcyI6W10sInNvdXJjZVJvb3QiOiIifQ== \ No newline at end of file diff --git a/360.bundle.js b/360.bundle.js new file mode 100644 index 0000000..5eb8839 --- /dev/null +++ b/360.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkcboy_blog=self.webpackChunkcboy_blog||[]).push([[360],{360:function(e,n,c){c.r(n),c.d(n,{default:function(){return t}});var r=c(358);const u={class:"component-readme"},o={};var t=(0,c(389).A)(o,[["render",function(e,n){return(0,r.uX)(),(0,r.CE)("div",u,n[0]||(n[0]=[(0,r.Lk)("h1",null,"cleverboy 的学习笔记",-1)]))}]])}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMzYwLmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoiNktBQWVBLE1BQU0sb0JDQ2ZDLEVBQVMsQ0FBQyxFQUtoQixPQUZpQyxFLE9BQUEsR0FBZ0JBLEVBQVEsQ0FBQyxDQUFDLFMsZ0NESmpEQyxFQUFBQSxFQUFBQSxJQUNKLE1BRElDLEVBQ0pDLEVBQUEsS0FBQUEsRUFBQSxLQURrQ0MsRUFBQUEsRUFBQUEsSUFBd0IsVUFBcEIsbUJBQWUsSyIsInNvdXJjZXMiOlsid2VicGFjazovL2Nib3ktYmxvZy8uLi8uLi9ibG9ncy9tYXJrZG93bi9yZWFkbWUubWQiLCJ3ZWJwYWNrOi8vY2JveS1ibG9nLy4uLy4uL2Jsb2dzL21hcmtkb3duL3JlYWRtZS5tZD8xZTYzIl0sInNvdXJjZXNDb250ZW50IjpbIjx0ZW1wbGF0ZT48ZGl2IGNsYXNzPVwiY29tcG9uZW50LXJlYWRtZVwiPjxoMT5jbGV2ZXJib3kg55qE5a2m5Lmg56yU6K6wPC9oMT5cbjwvZGl2PjwvdGVtcGxhdGU+IiwiaW1wb3J0IHsgcmVuZGVyIH0gZnJvbSBcIi4vcmVhZG1lLm1kP3Z1ZSZ0eXBlPXRlbXBsYXRlJmlkPWQ4ZTllMWQ0XCJcbmNvbnN0IHNjcmlwdCA9IHt9XG5cbmltcG9ydCBleHBvcnRDb21wb25lbnQgZnJvbSBcIi4uLy4uL25vZGVfbW9kdWxlcy8ucG5wbS92dWUtbG9hZGVyQDE3LjQuMl9AdnVlK2NvbXBpbGVyLXNmY0AzLjUuM192dWVAMy41LjNfdHlwZXNjcmlwdEA1LjUuNF9fd2VicGFja0A1Ljk0LjBfd2VicGFjay1fZnVxa3dnZ3BsaGV5M29pdnR3ZTJzdGRvNmUvbm9kZV9tb2R1bGVzL3Z1ZS1sb2FkZXIvZGlzdC9leHBvcnRIZWxwZXIuanNcIlxuY29uc3QgX19leHBvcnRzX18gPSAvKiNfX1BVUkVfXyovZXhwb3J0Q29tcG9uZW50KHNjcmlwdCwgW1sncmVuZGVyJyxyZW5kZXJdXSlcblxuZXhwb3J0IGRlZmF1bHQgX19leHBvcnRzX18iXSwibmFtZXMiOlsiY2xhc3MiLCJzY3JpcHQiLCJfY3JlYXRlRWxlbWVudEJsb2NrIiwiX2hvaXN0ZWRfMSIsIl9jYWNoZSIsIl9jcmVhdGVFbGVtZW50Vk5vZGUiXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/403.bundle.js b/403.bundle.js new file mode 100644 index 0000000..207760b --- /dev/null +++ b/403.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkcboy_blog=self.webpackChunkcboy_blog||[]).push([[403],{403:function(t,e,o){o.r(e),o.d(e,{default:function(){return i}});var s=o(358);const a={class:"component-aliyun-server"},c={};var i=(0,o(389).A)(c,[["render",function(t,e){return(0,s.uX)(),(0,s.CE)("div",a,e[0]||(e[0]=[(0,s.Fv)('

购买服务器

学生购买可以使用阿里云优惠专享, 每个月只要9.9 就好了。这里我用的是学生优惠,机型内存什么都限定好了的。所以- - 没什么可以说的。关于国内外服务器的区别就是,如果你购买了国外的服务器,就可以在云服务器上搭梯子访问国外的网站,也就是翻墙了。

安装环境

因为服务器默认 linux 系统,所以这里讲怎么配置 linux 云服务环境。 我第一次使用的时候,还以为是要去安装一个界面化桌面,以便我这个命令小白可以操作。但是,对于只有2G 的内存来说安装了之后将会很卡很卡。后来我问学长,他说不要安装界面化,使用命令就好了。

首先关于远程服务器的登录, 默认系统的用户名是 root, 然后登录密码可以在控制台进行修改。如下图点击重置密码。 重置密码处

重置之后,然后点击远程连接,就可以连接登录到你的服务器上了。这里要将一点,如果你是 mac 电脑的话,可以在你的电脑上通过 ssh 登录到你的服务器。 命令如下: ssh root@你的公网IP,比如 ssh root@120.78.32.12 然后输入密码即可连接成功。

登录成功图

接下来在终端中输入命令。配置环境。如果你是配置 java 环境,那么可以去谷歌一下如何在 linux 中配置 java 环境,这里我是配置的 node 环境,就讲一下如何配置 node 环境以及 npm。

这里我用的是源码安装。首先安装 node 编译依赖的第三方模块 yum -y install gcc make gcc-c++ openssl-devel

然后下载 node 的源码包 这里写图片描述

node 官网的源码 包。 wget https://nodejs.org/dist/v8.9.4/node-v8.9.4.tar.gz

你下载的时候可以手动改成当前最新版本。下载后,进行解压 tar -zxvf node-v8.9.4.tar.gz, 然后进入解压后的文件夹 cd node-v8.9.4, 依次 ./configure makesudo make install 这里编译时间会有点久,请耐心等待- - 查看安装成功 这里写图片描述

安装 npm 同样下载 npm 包 wget http://nodejs.org/dist/npm/npm-1.4.9.zip 解压 tar -zxvf npm-1.4.9.tgz 查看是否安装成功 npm -v

这就是 node 环境配置了, 然后就是 mysql 数据库。 http://blog.csdn.net/win7system/article/details/53579500

关于项目的上传,如果你本地编写了代码,想上传至服务器,第一个方式,可以是使用 ftp 上传文件。 第二个方式,就是在你的服务器上搭建一个 git 服务器,通过从服务器推送和克隆项目来获取文件。这里我使用的是第二种方法,参见教程: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770360579bc4b458f044ce7afed3df579123eca000 这里注意一下, 关于 设置 ssh 登录,一定要把创建的 .ssh 文件放到你创建的用户下,如我这里是 git 用户,路径就是 这里写图片描述

放置在正确位置之后,还要注意项目的归属者也要是 git 用户,这样才会在 git 用户里匹配到对应的 ssh key。也就是下面这一个步骤 这里写图片描述

还有一点要注意的就是,你再本地推送了代码上 git 服务器之后,想要在云服务器上获取到代码, 需要在服务器上再次克隆 git clone git@server:/srv/sample.git 项目,git pull 获取到代码。 这里也可以通过自己配置 git 服务器的钩子函数,使其自动更新代码,我还没配置,就先不说了 - -。

好了,现在现在基本环境配置好了就可以开始开发你的项目啦。

另外附: 项目在服务器上启动了,发现在本地电脑无法通过 ip 访问,那么可能是你的端口号没有开放,需要去服务器上设置安全组。 具体添加方法 ,以及其他一些关于服务器的配置,都可以随时点击右侧的 点我提问,像云博士提问。 = = 这里写图片描述

',19)]))}]])}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNDAzLmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoiNktBQWVBLE1BQU0sMkJDQ2ZDLEVBQVMsQ0FBQyxFQUtoQixPQUZpQyxFLE9BQUEsR0FBZ0JBLEVBQVEsQ0FBQyxDQUFDLFMsZ0NESmpEQyxFQUFBQSxFQUFBQSxJQTRDSixNQTVDSUMsRUE0Q0pDLEVBQUEsS0FBQUEsRUFBQSxLQTVDTkMsRUFBQUEsRUFBQUEsSUFBQSxrcUgiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9jYm95LWJsb2cvLi4vLi4vYmxvZ3MvbWFya2Rvd24vYWxpeXVuLXNlcnZlci5tZCIsIndlYnBhY2s6Ly9jYm95LWJsb2cvLi4vLi4vYmxvZ3MvbWFya2Rvd24vYWxpeXVuLXNlcnZlci5tZD85M2VlIl0sInNvdXJjZXNDb250ZW50IjpbIjx0ZW1wbGF0ZT48ZGl2IGNsYXNzPVwiY29tcG9uZW50LWFsaXl1bi1zZXJ2ZXJcIj48aDM+6LSt5Lmw5pyN5Yqh5ZmoPC9oMz5cbjxwPuWtpueUn+i0reS5sOWPr+S7peS9v+eUqOmYv+mHjOS6keS8mOaDoOS4k+S6q++8jCDmr4/kuKrmnIjlj6ropoE5Ljkg5bCx5aW95LqG44CC6L+Z6YeM5oiR55So55qE5piv5a2m55Sf5LyY5oOg77yM5py65Z6L5YaF5a2Y5LuA5LmI6YO96ZmQ5a6a5aW95LqG55qE44CC5omA5LulLSAtIOayoeS7gOS5iOWPr+S7peivtOeahOOAguWFs+S6juWbveWGheWkluacjeWKoeWZqOeahOWMuuWIq+WwseaYr++8jOWmguaenOS9oOi0reS5sOS6huWbveWklueahOacjeWKoeWZqO+8jOWwseWPr+S7peWcqOS6keacjeWKoeWZqOS4iuaQreair+WtkOiuv+mXruWbveWklueahOe9keerme+8jOS5n+WwseaYr+e/u+WimeS6huOAgjwvcD5cbjxoMz7lronoo4Xnjq/looM8L2gzPlxuPHA+5Zug5Li65pyN5Yqh5Zmo6buY6K6kIGxpbnV4IOezu+e7n++8jOaJgOS7pei/memHjOiusuaAjuS5iOmFjee9riBsaW51eCDkupHmnI3liqHnjq/looPjgIJcbuaIkeesrOS4gOasoeS9v+eUqOeahOaXtuWAme+8jOi/mOS7peS4uuaYr+imgeWOu+WuieijheS4gOS4queVjOmdouWMluahjOmdou+8jOS7peS+v+aIkei/meS4quWRveS7pOWwj+eZveWPr+S7peaTjeS9nOOAguS9huaYr++8jOWvueS6juWPquaciTJHIOeahOWGheWtmOadpeivtOWuieijheS6huS5i+WQjuWwhuS8muW+iOWNoeW+iOWNoeOAguWQjuadpeaIkemXruWtpumVv++8jOS7luivtOS4jeimgeWuieijheeVjOmdouWMlu+8jOS9v+eUqOWRveS7pOWwseWlveS6huOAgjwvcD5cbjxwPummluWFiOWFs+S6jui/nOeoi+acjeWKoeWZqOeahOeZu+W9le+8jCDpu5jorqTns7vnu5/nmoTnlKjmiLflkI3mmK8gcm9vdCwg54S25ZCO55m75b2V5a+G56CB5Y+v5Lul5Zyo5o6n5Yi25Y+w6L+b6KGM5L+u5pS544CC5aaC5LiL5Zu+54K55Ye76YeN572u5a+G56CB44CCXG48aW1nIHNyYz1cImh0dHBzOi8vaW1nLWJsb2cuY3Nkbi5uZXQvMjAxODAxMDcxNzAwNTQ5MTg/d2F0ZXJtYXJrLzIvdGV4dC9hSFIwY0RvdkwySnNiMmN1WTNOa2JpNXVaWFF2WkdGa1lXUmxaMkZ1YUhWdi9mb250LzVhNkw1TDJUL2ZvbnRzaXplLz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VyIH0gZnJvbSBcIi4vYWxpeXVuLXNlcnZlci5tZD92dWUmdHlwZT10ZW1wbGF0ZSZpZD1jNDRlNzg5MlwiXG5jb25zdCBzY3JpcHQgPSB7fVxuXG5pbXBvcnQgZXhwb3J0Q29tcG9uZW50IGZyb20gXCIuLi8uLi9ub2RlX21vZHVsZXMvLnBucG0vdnVlLWxvYWRlckAxNy40LjJfQHZ1ZStjb21waWxlci1zZmNAMy41LjNfdnVlQDMuNS4zX3R5cGVzY3JpcHRANS41LjRfX3dlYnBhY2tANS45NC4wX3dlYnBhY2stX2Z1cWt3Z2dwbGhleTNvaXZ0d2Uyc3RkbzZlL25vZGVfbW9kdWxlcy92dWUtbG9hZGVyL2Rpc3QvZXhwb3J0SGVscGVyLmpzXCJcbmNvbnN0IF9fZXhwb3J0c19fID0gLyojX19QVVJFX18qL2V4cG9ydENvbXBvbmVudChzY3JpcHQsIFtbJ3JlbmRlcicscmVuZGVyXV0pXG5cbmV4cG9ydCBkZWZhdWx0IF9fZXhwb3J0c19fIl0sIm5hbWVzIjpbImNsYXNzIiwic2NyaXB0IiwiX2NyZWF0ZUVsZW1lbnRCbG9jayIsIl9ob2lzdGVkXzEiLCJfY2FjaGUiLCJfY3JlYXRlU3RhdGljVk5vZGUiXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/520.bundle.js b/520.bundle.js new file mode 100644 index 0000000..b815573 --- /dev/null +++ b/520.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkcboy_blog=self.webpackChunkcboy_blog||[]).push([[520],{520:function(e,t,n){n.r(t),n.d(t,{default:function(){return p}});var o=n(358);const s={class:"component-pwa"},r={};var p=(0,n(389).A)(r,[["render",function(e,t){return(0,o.uX)(),(0,o.CE)("div",s,t[0]||(t[0]=[(0,o.Fv)('

什么是PWA

先说一下全名,progressive web app: 渐进式网页应用。这是谷歌推出的,我是这样理解的:

  • 我们一般写web应用,在 pc 上是没有缓存的,打开页面的时去请求数据。

  • 第二个也没有像 app 一样的小图标放在桌面,一点开就进入了应用,而是通过打开浏览器输入网址,

  • 第三个就是,不能像 app 一样给用户推送消息,像微博会跟你推送说有谁评论了你的微博之类的功能。

而谷歌推出的 pwa,就是具有这些了这些特点, 使我们的 web 应用,能够像一款 app 一样使用。并且对比与 app, 它不用复杂的安装,也不用下载更新包,刷新页面就可以了(注意到缓存的处理)。

那么这些功能分别是怎么实现的呢?

关于缓存

其实这个就是 我们平时做的 Session 啊、localStorage、CacheStorage 之类的。

这里用的就是 cacheStorage 缓存,它提供了一个ServiceWorker类型的工作者或window范围可以访问的所有命名缓存的主目录, 并维护字符串的映射名称到相应的 Cache 对象。 主要方法包括: 这里写图片描述 有了这些方法你可以对你的缓存进行操作。目前还在草案状态,仅火狐和谷歌浏览器支持此特性。

PWA是通过 ServiceWorker 访问 cache ,所以需要注册 ServiceWorker 工作者。在之前别忘记判断浏览器是否支持。

if ('serviceWorker' in navigator) {\n\tnavigator.serviceWorker.register(sw.js) // 注册sw.js 文件中变成的服务对象,返回注册成功的对象\n\t.then(function(swReg){\n          swRegistration = swReg;\n     }).catch(function(error) {\n          console.error('Service Worker Error', error);\n     });\n}\n

这个 Service Worker 服务工作者就厉害了,它相当于浏览器和网络之间的代理服务器,可以拦截网络请求,做一些你可能需要的处理(请求资源从缓存中获取等)。

  • 它能够创建有效的离线体验,拦截网络请求,并根据网络是否可用判断是否使用缓存数据或者更新缓存数据。

  • 它们还允许访问推送的通知和后台的API。

关于 sw.js 中具体的缓存的代码:

创建需要缓存的文件

'use strict'\nlet cacheName = 'pwa-demo-assets'; // 缓存名字\nlet imgCacheName = 'pwa-img';\nlet filesToCache;\nfilesToCache = [ // 所需缓存的文件\n    '/',\n    '/index.html',\n    '/scripts/app.js',\n    '/assets/imgs/48.png',\n    '/assets/imgs/96.png',\n    '/assets/imgs/192.png',\n    '/dist/js/app.js',\n    '/manifest.json'\n];\n\nself.addEventListener('install', function(e) {\n    e.waitUntil(\n\t    // 安装服务者时,对需要缓存的文件进行缓存\n        caches.open(cacheName).then(function(cache) {\n            return cache.addAll(filesToCache);\n        })\n    );\n});\n\n\nself.addEventListener('fetch', (e) => {\n    // 判断地址是不是需要实时去请求,是就继续发送请求\n    if (e.request.url.indexOf('/api/400/200') > -1) {\n        e.respondWith(\n            caches.open(imgCacheName).then(function(cache){\n                 return fetch(e.request).then(function (response){\n                    cache.put(e.request.url, response.clone()); // 每请求一次缓存更新一次新加载的图片\n                    return response;\n                });\n            })\n        );\n    } else {\n        e.respondWith(\n\t        // 匹配到缓存资源,就从缓存中返回数据\n            caches.match(e.request).then(function (response) {\n                return response || fetch(e.request);\n            })\n        );\n    }\n\n});\n

这里进而就引入到 pwa 的推送通知功能。这都是通过 ServiceWorker 去实现的。

基本原理是,你的客户端要和推送服务进行绑定,会生成一个绑定后的推送服务API接口,服务端调用此接口,发送消息。同时,浏览器也要支持推送功能,在注册 sw 时, 加上推送功能的判断。

if ('serviceWorker' in navigator && 'PushManager' in window) {\n\tnavigator.serviceWorker.register(sw.js)\n\t.then(function(swReg) {\n        swRegistration = swReg;\n    }).catch(function(error) {\n        console.error('Service Worker Error', error);\n        });\n } else {\n     console.warn('Push messaging is not supported');\n }\n

PushManager 注册好之后, 那么要做的就是浏览器和服务器的绑定了。

这里写图片描述 此图是用户订阅某个应用程序的推送服务。 客户端传入应用程序服务器公钥,向将生成端点的 webpush 服务器( 这是谷歌自己实现的一个推送功能的服务器)发出网络请求,将生成的端点(一个推送服务)与应用程序公钥关联,并将端点返回给应用程序。浏览器会将此端点添加到 PushSubscription,通过 promise异步成功时,可以将它的信息保存到你的数据库。

这里写图片描述 服务器发送推送的时候,请求相关接口,验证成功后推送服务会发消息给客户端。

最后关于桌面小图标

这个可以说是非常简单了,就是一个manifest.json配置文件,然后在页面引入此文件就好了

<!-- 加载清单 -->\n<link rel="manifest" href="./manifest.json">\n

关于清单内容这里简单介绍一下:

{\n    "short_name": "pwa",\n    "name": "pwa - demo", // 应用名称\n    "icons": [ // 应用显示图标,根据容器大小适配\n        {\n            "src": "assets/imgs/48.png",\n            "type": "image/png",\n            "sizes": "48x48"\n        },\n        {\n            "src": "assets/imgs/96.png",\n            "type": "image/png",\n            "sizes": "96x96"\n        },\n        {\n            "src": "assets/imgs/192.png",\n            "type": "image/png",\n            "sizes": "192x192"\n        }\n    ],\n    "background_color": "#2196F3", // 刚打开页面时的背景\n    "theme_color": "#2196F3", // 主题颜色\n    "display": "standalone", //独立显示\n    "start_url": "index.html?launcher=true" // 启动的页面\n}\n

好了, 如果感兴趣赶快上手吧。 可以查看谷歌官方教程

这里说一下坑的点, PWA应用需要在本地localhost:8080 上运行或者 https 协议下, 要保证你的页面是安全页面。

添加桌面时,确保你的谷歌浏览器可以显示弹出通知。

如果你要自己实现推送,自己服务器要有公钥和私钥的获取, 这里可以通过 https://web-push-codelab.glitch.me 获取, 用 chrome 的 webpush 推送。

这里也可以看一下我的 GitHub 项项目 ,官方也有很多例子。

',31)]))}]])}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNTIwLmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoiNktBQWVBLE1BQU0saUJDQ2ZDLEVBQVMsQ0FBQyxFQUtoQixPQUZpQyxFLE9BQUEsR0FBZ0JBLEVBQVEsQ0FBQyxDQUFDLFMsZ0NESmpEQyxFQUFBQSxFQUFBQSxJQWtKSixNQWxKSUMsRUFrSkpDLEVBQUEsS0FBQUEsRUFBQSxLQWxKTkMsRUFBQUEsRUFBQUEsSUFBQSwyZ00iLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9jYm95LWJsb2cvLi4vLi4vYmxvZ3MvbWFya2Rvd24vcHdhLm1kIiwid2VicGFjazovL2Nib3ktYmxvZy8uLi8uLi9ibG9ncy9tYXJrZG93bi9wd2EubWQ/NTNiNCJdLCJzb3VyY2VzQ29udGVudCI6WyI8dGVtcGxhdGU+PGRpdiBjbGFzcz1cImNvbXBvbmVudC1wd2FcIj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uPHA+5YWz5LqOPGEgaHJlZj1cImh0dHBzOi8vZGV2ZWxvcGVycy5nb29nbGUuY29tL3dlYi9mdW5kYW1lbnRhbHMvd2ViLWFwcC1tYW5pZmVzdC9cIj7muIXljZXlhoXlrrk8L2E+6L+Z6YeM566A5Y2V5LuL57uN5LiA5LiL77yaPC9wPlxuPHByZSB2LXByZT1cIlwiPjxjb2RlPntcbiAgICBcInNob3J0X25hbWVcIjogXCJwd2FcIixcbiAgICBcIm5hbWVcIjogXCJwd2EgLSBkZW1vXCIsIC8vIOW6lOeUqOWQjeensFxuICAgIFwiaWNvbnNcIjogWyAvLyDlupTnlKjmmL7npLrlm77moIfvvIzmoLnmja7lrrnlmajlpKflsI/pgILphY1cbiAgICAgICAge1xuICAgICAgICAgICAgXCJzcmNcIjogXCJhc3NldHMvaW1ncy80OC5wbmdcIixcbiAgICAgICAgICAgIFwidHlwZVwiOiBcImltYWdlL3BuZ1wiLFxuICAgICAgICAgICAgXCJzaXplc1wiOiBcIjQ4eDQ4XCJcbiAgICAgICAgfSxcbiAgICAgICAge1xuICAgICAgICAgICAgXCJzcmNcIjogXCJhc3NldHMvaW1ncy85Ni5wbmdcIixcbiAgICAgICAgICAgIFwidHlwZVwiOiBcImltYWdlL3BuZ1wiLFxuICAgICAgICAgICAgXCJzaXplc1wiOiBcIjk2eDk2XCJcbiAgICAgICAgfSxcbiAgICAgICAge1xuICAgICAgICAgICAgXCJzcmNcIjogXCJhc3NldHMvaW1ncy8xOTIucG5nXCIsXG4gICAgICAgICAgICBcInR5cGVcIjogXCJpbWFnZS9wbmdcIixcbiAgICAgICAgICAgIFwic2l6ZXNcIjogXCIxOTJ4MTkyXCJcbiAgICAgICAgfVxuICAgIF0sXG4gICAgXCJiYWNrZ3JvdW5kX2NvbG9yXCI6IFwiIzIxOTZGM1wiLCAvLyDliJrmiZPlvIDpobXpnaLml7bnmoTog4zmma9cbiAgICBcInRoZW1lX2NvbG9yXCI6IFwiIzIxOTZGM1wiLCAvLyD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+6L+Z6YeM5Lmf5Y+v5Lul55yL5LiA5LiL5oiR55qEPGEgaHJlZj1cImh0dHBzOi8vZ2l0aHViLmNvbS9jbGV2ZXJib3kzMi9jaG9ybWUtUHdhRGVtb1wiPiBHaXRIdWIg6aG56aG555uuIDwvYT7vvIzlrpjmlrnkuZ/mnInlvojlpJrkvovlrZDjgII8L3A+XG48L2Rpdj48L3RlbXBsYXRlPiIsImltcG9ydCB7IHJlbmRlciB9IGZyb20gXCIuL3B3YS5tZD92dWUmdHlwZT10ZW1wbGF0ZSZpZD03OGJiYjdkYlwiXG5jb25zdCBzY3JpcHQgPSB7fVxuXG5pbXBvcnQgZXhwb3J0Q29tcG9uZW50IGZyb20gXCIuLi8uLi9ub2RlX21vZHVsZXMvLnBucG0vdnVlLWxvYWRlckAxNy40LjJfQHZ1ZStjb21waWxlci1zZmNAMy41LjNfdnVlQDMuNS4zX3R5cGVzY3JpcHRANS41LjRfX3dlYnBhY2tANS45NC4wX3dlYnBhY2stX2Z1cWt3Z2dwbGhleTNvaXZ0d2Uyc3RkbzZlL25vZGVfbW9kdWxlcy92dWUtbG9hZGVyL2Rpc3QvZXhwb3J0SGVscGVyLmpzXCJcbmNvbnN0IF9fZXhwb3J0c19fID0gLyojX19QVVJFX18qL2V4cG9ydENvbXBvbmVudChzY3JpcHQsIFtbJ3JlbmRlcicscmVuZGVyXV0pXG5cbmV4cG9ydCBkZWZhdWx0IF9fZXhwb3J0c19fIl0sIm5hbWVzIjpbImNsYXNzIiwic2NyaXB0IiwiX2NyZWF0ZUVsZW1lbnRCbG9jayIsIl9ob2lzdGVkXzEiLCJfY2FjaGUiLCJfY3JlYXRlU3RhdGljVk5vZGUiXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/551.bundle.js b/551.bundle.js new file mode 100644 index 0000000..a926b3d --- /dev/null +++ b/551.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkcboy_blog=self.webpackChunkcboy_blog||[]).push([[551],{551:function(e,n,t){t.r(n),t.d(n,{default:function(){return s}});var r=t(358);const o={class:"component-typescript"},p={};var s=(0,t(389).A)(p,[["render",function(e,n){return(0,r.uX)(),(0,r.CE)("div",o,n[0]||(n[0]=[(0,r.Fv)('

learn typescript

类型

基本类型:

string number bool \n

数组 []:

string[]  number[]\n

元祖:

[string, number]. 数组中有不同的数据类型\n

对象:

{ name: string; age: number }\n

函数:

(arg1: string, arg?: bool) => void\n

Symbol:

let symbol = Symbol("key"); \n

空:

undefined   null\n

任何类型:

any\n

不存在的值:

never\n

如何定义类型

type 定义类型变量

type Person = { name: string; age: number}\nts 使用 const person1:Person = { name: '22', age: 1};\n

Interfaces 声明 对象 类型的一种方法

Interface Person { name: string; age: number}\n

extends 类型继承于声明的类型

interface a { name: string}\ninterface b extends a {\n\tage: number\n}\nb 的类型等于 { name: string; age: number }\n

in 判断属性是哪个类型中的

type PersonListQuery = { user_ids: string[] }\ntype DogListQuery = { dog_ids: string[] }\n\nfunction getList(query: PersonListQuery | DogListQuery ) {\n\tif ('user_ids' in PersonListQuery) {\n\t \t// 这里可以推导出 query 类型是 PersonListQuery\n\t}\n}\n\n

类型组合

Required<T> 将 T 中所有属性变成必选

Required<{ a?: bool} > = { a: bool }\n

Partial<T> 将 T 中所有属性变成可选

Partial<{ a: bool }> = { a?: bool }\n

Readonly<T> 将 T 中所有属性变成只读,后续 ts 会检测该类型不允许修改

const person2: Readonly<{name: string}> = {name: '22'}\nperson2.name = '33' //error\n

Omit<T, keys> 删除某些属性

interface Person {\n  name: string;\n  age: number;\n}\n \ntype Name = Omit<Person, 'age'>;\nName 的类型定义为 { name: string }\n

Pick<T, keys> 选择类型中的某些属性

interface Person {\n  name: string;\n  age: number;\n}\ntype Name = Pick<Person, 'name'>;\nName 的类型定义为 { name: string }\n

Exclude<T, deleteT> 删除类型 T 中 deleteT 的类型, 相当于 Omit, 第二个值可以是 keys ,也可以是一个类型变量

interface Person {\n  name: string;\n  age: number;\n}\ntype Age = { age: number }\ntype Name = Exclude<Person, Age>\nName 的类型定义为 { name: string }\n

Extract<T, U> 提取 T 继承于的 U 类型

type Person = {  name: string ; age: number } \ntype PersonDetail = { pet: any; phone: number } \ntype Name = { name: string }\ntype Name = Extract<Person | PersonDetail , Name>\n 将提取出含有 name 的类型 Person\n

Parameters<function T> 获取函数类型的函数类型

type getName = (perpson: Person) => string;\ntype queryType = Parameters<getName>;\nqueryType  的类型定义为 Person\n

ReturnType<function T> 获取函数类型的返回值类型

type getName = (perpson: Person) => string;\ntype resType = ReturnType<getName>;\nvalueType 类型为 string\n

Awaited<Promise Type> 获取异步返回的值类型

type getPerson = (id: string) => Promise<Person>\ntype resType = ReturnType<getPerson> // Promise<Person>\ntype valueType = Awaited<resType> // Person\n

Record<K extends keyof any, T> 定义对象的 key 键类型

type Keys = 'name' | 'age' \ntype person = Record<Keys, any>\n// person 的属性只能为 name 和 age\n

NonNullable<T> 去除类型中定义的 null 和 undefined

type PersonHobby = hobby: string | undefined;\ntype Hobby = NonNullable<hobby>\nHobby 类型为  string\n

类型操作

typeof Object 获得对象的类型

const person1 = { name: '22', age: 1}\ntype Person = typeof person1\nPerson 类型为 { name: string; age: number }\n

keyof T 获得类型中的属性

type Person = { name: string; age: number }\ntype Key = keyof Person \nkey 的类型为 'name' | 'age'\n

通常我们可以通过 keyof 约束对象的传参, 如

type Person = { name: string; age: number }\ntype Key = keyof Person;\ntype getPersonAtrribute = (person: Person, key: Key) => Person[Key];\n

或者某些情况下我们想知道一个对象的属性值

const workPerson = { \n\t'1': { name: '1', age: 1},\n\t'2': { name: '2', age: 2},\n}\ntype WorkPerson  = typeof workPerson;  // { '1': {name: string; age: number }, '2': {name: string; age: number }\ntype Key = keyof WorkPerson  // '1' | '2'\ntype Person = WorkPerson[Key]   // {name: string; age: number }\n

| 类型兼容

type width = 'string' | 'number';\n\n则 width 可以是 '32px' 也可以是 '32' 在 渲染时兼容两种类型\n

函数重载

定义不同类型的输入,推到出不同类型的输出

type PersonListQuery = { user_ids: string[] };\ntype DongListQuery = { dog_ids: string[] };\nfunction getList(request: PersonListQuery): Person[];\nfunction getList(request: DogListQuery): Dog[];\n\nfunction getList(query: PersonListQuery | DogListQuery) {\n  if ('user_ids' in query) {  \n    return [] as Person[];\n  } else {\n    return [] as Dog[];\n  }\n}\n\nconst a = getList({ personIds: [], region: 'us'})\n此时 a 的类型将能推到出是 Person[]\n

泛型

类型的传参。 用 T 标识,在实际运用时你传入什么类型,该类型就作为后续推导。

async function request<T>(url: string): Promise<T> {\n  const res = await fetch(url)\n  return res.json();\n}\n\nconst res = await request<Person>('getPersonInfo?id=1'); \n此时 ts 可以推导出 res 的类型是 Person\n

Infer 类型参数使用

通过 Infer 一个类型为变量,定义出获取类型的方法

type addResultType<T> = T extends { a: infer U, b: infer U } ?  U : never;\ntype numberAdd =  addResultType<{ a: 1, b: 2 }>     // 推到出结果类型为 number\ntype textAdd = addResultType<{ a: 'hello', b: 'world' }>     // 推到出结果类型为 string\n

枚举 enum

变量的值是约定的几个取值

const enum PageType {\n  HOME = 'home',\n  VIDEO = 'video',\n}\n\nfunction getPageUrl(page: PageType) {\n  return {\n    [PageType.VIDEO]: "/video",\n    [PageType.HOME]: "/home",\n  }[page];\n}\n

tsconfig

了解了 ts 对于类型的定义和各种规则后,我们则可以在编写 js 代码时利用并进行类型约束。于此同时,我们需要引入 typescript 库去获得这些 ts 能力。

如何引入

npm install  typescript  \n// 不必再多说\n

命令

typescript 包是有命令文件的,通常 ts 的运行则是通过 tsc 配合相关命令去执行的. 具体命令大家可以安装包之后通过 tsc -h 查看 在这里插入图片描述

配置 官网

如果你看了 tsc 命令,你会发现它是有很多命令的,并且有的命令还伴随这相关参数。在工作文件夹中,我们则通过配置文件 tsconfig.js 去配置,保证在项目中的运用。 配置参数这里就不细讲了,还是看官方文档靠谱点。

',85)]))}]])}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNTUxLmJ1bmRsZS5qcyIsIm1hc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Y2xhc3MiLCJzY3JpcHQiLCJfY3JlYXRlRWxlbWVudEJsb2NrIiwiX2hvaXN0ZWRfMSIsIl9jYWNoZSIsIl9jcmVhdGVTdGF0aWNWTm9kZSJdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/627.bundle.js b/627.bundle.js new file mode 100644 index 0000000..278bdf1 --- /dev/null +++ b/627.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkcboy_blog=self.webpackChunkcboy_blog||[]).push([[627],{627:function(e,n,t){t.r(n),t.d(n,{default:function(){return i}});var o=t(358);const r={class:"component-module"},c={};var i=(0,t(389).A)(c,[["render",function(e,n){return(0,o.uX)(),(0,o.CE)("div",r,n[0]||(n[0]=[(0,o.Fv)('

当我们要完成一个应用的时候,会根据对应的功能划分为许多不同的模块,就像一个论坛,有发帖的模块,评论的模块,js 中的模块也正是如此,一个具体功能的代码抽成一个文件,当你做一个东西的时候需要用到这个功能的时,可以直接使用这个文件,实现功能的分离,并能在多个需要的地方使用。就像是螺丝钉、螺丝帽、垫片一样的,通过组合使用实现出你的产品。

通过直白的描述,我们可以知道,模块化的好处就是,抽离代码,重复使用,如现在很直观的代表 npm 包。

那么模块化到底是怎么实现的呢?

先来了解一下历史,以前的 html 不知道大家还记不记的, 一个html 页面引入了多个 js 文件.

<!DOCTYPE html>\n<html lang="zh-CN">\n<head>\n    <meta charset="UTF-8">\n    <title>So UI - A Component Library for Vue.js.</title>\n</head>\n<body>\n    <div id="app"></div>\n    <script src="a.js"></script>\n    <script src="b.js"></script>\n    <script src="c.js"></script>\n    <script src="d.js"></script>\n    <script src="e.js"></script>\n</body>\n</html>\n

如上,引入了 a/b/c/d/e 五个文件,这五个文件如果相互之间有依赖,还要注意引入的顺序,并且还需要注意它们里面的变量名,若是重复利用到其他的项目,其他项目也需要注意到以上两点问题。为了解决这一问题,就有了模块化的规范。

模块化的规范,有 CMDAMD

CMD (Common Module Definition), 是sea.js在推广过程中对模块定义的规范化产出,主要用于浏览器端。它主要特点是:对于依赖的模块是延迟执行,依赖可以就近书写,等到需要用这个依赖的时候再引入这个依赖,应用有sea.js.

AMD规范(Asynchronous Module Definition):是 RequireJS 在推广过程中对模块定义的规范化产出,也是主要用于浏览器端。其特点是:依赖前置,需要在定义时就写好需要的依赖,提前执行依赖,应用有require.js

尽情的猜测,require.js 是怎么弄的呢? 它需要依次的加载模块然后去进行相应的操作,加载模块就是要引入这个文件,那么这里也还是通过动态加载 script 的方法,并通过 onload 去执行后面的回调了。

我们知道现如今 es6 已经支持模块化了,它分为 export 和 import 两个命令。 export 导出你定义的模块变量, import 引入一个模块变量。

export { \n \tone, \n \ttwo\n }\n export default three;\n

对应的引入代码

import  { one, two }  three from 'a.js'\n

可以看到 export 可以导出一个默认的变量,也可以导出变量对象,这里引入的时候名字不要写错了。 那么 es6 的模块化通过babel 转码其实就是 umd 模块规范, 它是一个兼容 cmd 和 amd 的模块化规范, 同时还支持老式的“全局”变量规范

(function (root, factory) {\n    if (typeof define === 'function' && define.amd) {\n        // AMD\n        define(['jquery'], factory);\n    } else if (typeof exports === 'object') {\n        // Node, CommonJS之类的\n        module.exports = factory(require('jquery'));\n    } else {\n        // 浏览器全局变量(root 即 window)\n        root.returnExports = factory(root.jQuery);\n    }\n}(this, function ($) {\n    //    方法\n    function myFunc(){};\n \n    //    暴露公共方法\n    return myFunc;\n}));\n

那么浏览器是如何支持这种规范的呢? 其实是实现了根据这种规范定制出来的功能。这里我们就按照 实现了 AMD 规范的 require.js 来讲一下实现代码。

AMD 定义一个模块的方法是 define(id?, dependencies?, factory)。

参考define 的方法代码

 define = function (name, deps, callback) {\n        var node, context;\n        \n        //Allow for anonymous modules\n        if (typeof name !== 'string') {\n            //Adjust args appropriately\n            callback = deps;\n            deps = name;\n            name = null;\n        }\n\n        //This module may not have dependencies\n        if (!isArray(deps)) {\n            callback = deps;\n            deps = null;\n        }\n\n        //If no name, and callback is a function, then figure out if it a\n        //CommonJS thing with dependencies.\n        if (!deps && isFunction(callback)) {\n            deps = [];\n            //移除注释\n            //查找 require 语句,收集依赖到 deps 里面\n            // but only if there are function args.\n            if (callback.length) {\n                callback\n                    .toString()\n                    .replace(commentRegExp, commentReplace)\n                    .replace(cjsRequireRegExp, function (match, dep) {\n                        deps.push(dep);\n                    });\n\n                //May be a CommonJS thing even without require calls, but still\n                //could use exports, and module. Avoid doing exports and module\n                //work though if it just needs require.\n                //REQUIRES the function to expect the CommonJS variables in the\n                //order listed below.\n                deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps);\n            }\n        }\n\n        //If in IE 6-8 and hit an anonymous define() call, do the interactive\n        //work.\n        if (useInteractive) {\n            node = currentlyAddingScript || getInteractiveScript();\n            if (node) {\n                if (!name) {\n                    name = node.getAttribute('data-requiremodule');\n                }\n                context = contexts[node.getAttribute('data-requirecontext')];\n            }\n        }\n\n        //Always save off evaluating the def call until the script onload handler.\n        //This allows multiple modules to be in a file without prematurely\n        //tracing dependencies, and allows for anonymous module support,\n        //where the module name is not known until the script onload event\n        //occurs. If no context, use the global queue, and get it processed\n        //in the onscript load callback.\n        if (context) {\n            context.defQueue.push([name, deps, callback]);\n            context.defQueueMap[name] = true;\n        } else {\n            globalDefQueue.push([name, deps, callback]);\n        }\n    };\n\n    define.amd = {\n        jQuery: true\n    };\n    \n\treq.exec = function (text) {\n        /*jslint evil: true */\n        return eval(text);\n    };\n\n    //Set up with config info.\n    req(cfg);\n

可以知道,这一段代码是解析定义是模块所需的依赖放置 context 的模块定义队列中。然后我们就要通过 req 去执行加载依赖,我们来看看 req 的定义。

req = requirejs = function (deps, callback, errback, optional) {\n\n        //Find the right context, use default\n        var context, config,\n            contextName = defContextName;\n\n        // Determine if have config object in the call.\n        if (!isArray(deps) && typeof deps !== 'string') {\n            // deps is a config object\n            config = deps;\n            if (isArray(callback)) {\n                // Adjust args if there are dependencies\n                deps = callback;\n                callback = errback;\n                errback = optional;\n            } else {\n                deps = [];\n            }\n        }\n\n        if (config && config.context) {\n            contextName = config.context;\n        }\n       \n        if (config) {\n            context.configure(config); // 完善配置\n        }\n\n        return context.require(deps, callback, errback); \n

这里的代码把 依赖,回调, 错误处理和配置项都传进来了,进行了配置上的处理之后,我们可以看到最后再去根据配置加载。 我们再来看 context.require 方法

makeRequire: function (relMap, options) {\n\t\toptions = options || {};\n\t\tfunction localRequire(deps, callback, errback) {\n\t\t\t.... 当前 require 的转换\n      \t \treturn localRequire;\n  \t\t }\n\t\tcompleteLoad: function (moduleName) {\n\t\t\t判断 context 的依赖队列,是继续加载还是执行回调\n\t\t}\n\t\t nameToUrl: function (moduleName, ext, skipExt) {\n\t\t \t根据模块名和配置得到加载的路径\n\t\t }\n\t\t load: function (id, url) {\n\t               req.load(context, id, url);\n\t      },\n\t      execCb: function (name, callback, args, exports) {\n\t                return callback.apply(exports, args);\n\t        },\n\t\tonScriptLoad: function (evt) {\n\t\t\t脚本加载完成后得到数据,执行 context.completeLoad(data.id);\n\t\t}\n\t\tonScriptError: function (evt) {\n\t\t\t加载错误执行错误处理\n\t\t}\n\t};\n   context.require = context.makeRequire();\n

那我们知道其实就是围着这语法的解析,进行一系列的脚本加载,然后执行回调。

',25)]))}]])}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNjI3LmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoiNktBQWVBLE1BQU0sb0JDQ2ZDLEVBQVMsQ0FBQyxFQUtoQixPQUZpQyxFLE9BQUEsR0FBZ0JBLEVBQVEsQ0FBQyxDQUFDLFMsZ0NESmpEQyxFQUFBQSxFQUFBQSxJQXVNSixNQXZNSUMsRUF1TUpDLEVBQUEsS0FBQUEsRUFBQSxLQXZNTkMsRUFBQUEsRUFBQUEsSUFBQSxtOE8iLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9jYm95LWJsb2cvLi4vLi4vYmxvZ3MvbWFya2Rvd24vbW9kdWxlLm1kIiwid2VicGFjazovL2Nib3ktYmxvZy8uLi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gYSBmdW5jdGlvbiwgdGhlbiBmaWd1cmUgb3V0IGlmIGl0IGFcbiAgICAgICAgLy9Db21tb25KUyB0aGluZyB3aXRoIGRlcGVuZGVuY2llcy5cbiAgICAgICAgaWYgKCFkZXBzICZhbXA7JmFtcDsgaXNGdW5jdGlvbihjYWxsYmFjaykpIHtcbiAgICAgICAgICAgIGRlcHMgPSBbXTtcbiAgICAgICAgICAgIC8v56e76Zmk5rOo6YeKXG4gICAgICAgICAgICAvL+afpeaJviByZXF1aXJlIOivreWPpe+8jOaUtumbhuS+nei1luWIsCBkZXBzIOmHjOmdolxuICAgICAgICAgICAgLy8gYnV0IG9ubHkgaWYgdGhlcmUgYXJlIGZ1bmN0aW9uIGFyZ3MuXG4gICAgICAgICAgICBpZiAoY2FsbGJhY2subGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgY2FsbGJhY2tcbiAgICAgICAgICAgICAgICAgICAgLnRvU3RyaW5nKClcbiAgICAgICAgICAgICAgICAgICAgLnJlcGxhY2UoY29tbWVudFJlZ0V4cCwgY29tbWVudFJlcGxhY2UpXG4gICAgICAgICAgICAgICAgICAgIC5yZXBsYWNlKGNqc1JlcXVpcmVSZWdFeHAsIGZ1bmN0aW9uIChtYXRjaCwgZGVwKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBkZXBzLnB1c2goZGVwKTtcbiAgICAgICAgICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgICAgICAvL01heSBiZSBhIENvbW1vbkpTIHRoaW5nIGV2ZW4gd2l0aG91dCByZXF1aXJlIGNhbGxzLCBidXQgc3RpbGxcbiAgICAgICAgICAgICAgICAvL2NvdWxkIHVzZSBleHBvcnRzLCBhbmQgbW9kdWxlLiBBdm9pZCBkb2luZyBleHBvcnRzIGFuZCBtb2R1bGVcbiAgICAgICAgICAgICAgICAvL3dvcmsgdGhvdWdoIGlmIGl0IGp1c3QgbmVlZHMgcmVxdWlyZS5cbiAgICAgICAgICAgICAgICAvL1JFUVVJUkV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K3jgILnhLblkI7miJHku6zlsLHopoHpgJrov4cgcmVxIOWOu+aJp+ihjOWKoOi9veS+nei1lu+8jOaIkeS7rOadpeeci+eciyByZXEg55qE5a6a5LmJ44CCPC9wPlxuPHByZSB2LXByZT1cIlwiPjxjb2RlPnJlcSA9IHJlcXVpcmVqcyA9IGZ1bmN0aW9uIChkZXBzLCBjYWxsYmFjaywgZXJyYmFjaywgb3B0aW9uYWwpIHtcblxuICAgICAgICAvL0ZpbmQgdGhlIHJpZ2h0IGNvbnRleHQsIHVzZSBkZWZhdWx0XG4gICAgICAgIHZhciBjb250ZXh0LCBjb25maWcsXG4gICAgICAgICAgICBjb250ZXh0TmFtZSA9IGRlZkNvbnRleHROYW1lO1xuXG4gICAgICAgIC8vIERldGVybWluZSBpZiBoYXZlIGNvbmZpZyBvYmplY3QgaW4gdGhlIGNhbGwuXG4gICAgICAgIGlmICghaXNBcnJheShkZXBzKSAmYW1wOyZhbXA7IHR5cGVvZiBkZXBzICE9PSAnc3RyaW5nJykge1xuICAgICAgICAgICAgLy8gZGVwcyBpcyBhIGNvbmZpZyBvYmplY3RcbiAgICAgICAgICAgIGNvbmZpZyA9IGRlcHM7XG4gICAgICAgICAgICBpZiAoaXNBcnJheShjYWxsYmFjaykpIHtcbiAgICAgICAgICAgICAgICAvLyBBZGp1c3QgYXJncyBpZiB0aGVyZSBhcmUgZGVwZW5kZW5jaWVzXG4gICAgICAgICAgICAgICAgZGVwcyA9IGNhbGxiYWNrO1xuICAgICAgICAgICAgICAgIGNhbGxiYWNrID0gZXJyYmFjaztcbiAgICAgICAgICAgICAgICBlcnJiYWNrID0gb3B0aW9uYWw7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGRlcHMgPSBbXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChjb25maWcgJmFtcDsmYW1wOyBjb25maWcuY29udGV4dCkge1xuICAgICAgICAgICAgY29udGV4dE5hbWUgPSB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AxNy40LjJfQHZ1ZStjb21waWxlci1zZmNAMy41LjNfdnVlQDMuNS4zX3R5cGVzY3JpcHRANS41LjRfX3dlYnBhY2tANS45NC4wX3dlYnBhY2stX2Z1cWt3Z2dwbGhleTNvaXZ0d2Uyc3RkbzZlL25vZGVfbW9kdWxlcy92dWUtbG9hZGVyL2Rpc3QvZXhwb3J0SGVscGVyLmpzXCJcbmNvbnN0IF9fZXhwb3J0c19fID0gLyojX19QVVJFX18qL2V4cG9ydENvbXBvbmVudChzY3JpcHQsIFtbJ3JlbmRlcicscmVuZGVyXV0pXG5cbmV4cG9ydCBkZWZhdWx0IF9fZXhwb3J0c19fIl0sIm5hbWVzIjpbImNsYXNzIiwic2NyaXB0IiwiX2NyZWF0ZUVsZW1lbnRCbG9jayIsIl9ob2lzdGVkXzEiLCJfY2FjaGUiLCJfY3JlYXRlU3RhdGljVk5vZGUiXSwic291cmNlUm9vdCI6IiJ9 \ No newline at end of file diff --git a/643.bundle.js b/643.bundle.js new file mode 100644 index 0000000..90100ac --- /dev/null +++ b/643.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkreact_wyz=self.webpackChunkreact_wyz||[]).push([[643],{643:(n,t,i)=>{i.r(t),i.d(t,{default:()=>o});const o='作为一个前端,写页面结构,写CSS怎么命名? \n就算不用,但你的了解, 让自己的代码更规范。\n\n##### BEM是什么\n它是css命名的一种规范。试想,你写了一个页面,有input, button, div, 这些元素是什么样的关系,给他们添加样式的时候,怎么知道他们是一个页面的? 怎么知道input 是否放在div里面的? 不要急,这就说到了下面的命名之作用\n\n#### BEM是怎么命名的\n```html\n\n\t
\n\t\t\n\t\t\t\n\t
\n\n```\n通过上面命名可以很直接看出,input 和button 在div 里面。\n这里讲 后面的 __input/__confim 这里后面接两个下划线,表示的是div里面的子元素。\n```html\n\n\t
\n\t\t\n\t\t\t\n\t
\n\n```\n这里说, --big表示添加的描述, 很明显是大的注册表单的样式嘛。\n\n#### BEM总结\n好了, 这里loggin-from 相当于一块整体(block), 里面包含了元素input/button(element), 还有这个块或者一些元素的修饰big(modifier) => BEM\n它一般和sass一起使用,在用@C代表块、 @d代表元素、 @m代码修饰符的时候, css可以这样写了\n```\n@C loggin-from {\n\twidth: 100px;\n\theight: 100px;\n\t@m big {\n\t\twidth: 200px;\n\t\theight: 200px;\n\t}\n\t@d input {\n\t\tcolor: red;\n\t}\n\t@d button {\n\t\tcolor: blue;\n\t}\n}\n```\n怎么样,这样是不是就不用写那么长了, 而且一看样式文件,就能知道页面布局是什么样的。\n**以上写法, 要通过sass 插件配置的**\n这里有一个包 ,可以使用[sass-bem-constructor](https://www.npmjs.com/package/sass-bem-constructor)'}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNjQzLmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoia0lBQUEsNnFDIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vcmVhY3Rfd3l6Ly4uLy4uL2Jsb2dzL21hcmtkb3duL2JlbS5tZCJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCBcIuS9nOS4uuS4gOS4quWJjeerr++8jOWGmemhtemdoue7k+aehO+8jOWGmUNTU+aAjuS5iOWRveWQjT8gXFxu5bCx566X5LiN55So77yM5L2G5L2g55qE5LqG6Kej77yMIOiuqeiHquW3seeahOS7o+eggeabtOinhOiMg+OAglxcblxcbiMjIyMjIEJFTeaYr+S7gOS5iFxcbuWug+aYr2Nzc+WRveWQjeeahOS4gOenjeinhOiMg+OAguivleaDs++8jOS9oOWGmeS6huS4gOS4qumhtemdou+8jOaciWlucHV0LCBidXR0b24sIGRpdiwg6L+Z5Lqb5YWD57Sg5piv5LuA5LmI5qC355qE5YWz57O777yM57uZ5LuW5Lus5re75Yqg5qC35byP55qE5pe25YCZ77yM5oCO5LmI55+l6YGT5LuW5Lus5piv5LiA5Liq6aG16Z2i55qE77yfIOaAjuS5iOefpemBk2lucHV0IOaYr+W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1Y3RvcilcIjsiXSwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiIn0= \ No newline at end of file diff --git a/658.bundle.js b/658.bundle.js new file mode 100644 index 0000000..6073d76 --- /dev/null +++ b/658.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkcboy_blog=self.webpackChunkcboy_blog||[]).push([[658],{658:function(e,p,o){o.r(p),o.d(p,{default:function(){return d}});var c=o(358);const h={class:"component-safe"},s={};var d=(0,o(389).A)(s,[["render",function(e,p){return(0,c.uX)(),(0,c.CE)("div",h,p[0]||(p[0]=[(0,c.Fv)('

安全意识

你要离开家了, 所有的父母都会说,路上注意安全,可见安全是多么的重要!那么作为软件开发,有哪些危险使我们要知道并避免的呢? 下面我说一些基本的需要知道的安全攻击, 以及应对方案。

ps 作为一个安全小白,了解各种各样的防范方案真的太难了,我是真的水🤭。欢迎补充,以增长见识

XSS: 跨站脚本攻击

在用户可以输入的地方,并且将作为代码编译时,攻击者可以通过输入一个脚本地址的方式进行对页面注入脚本攻击。解决方式: 任何用户输入的地方都不要相信,对用户输入内容进行转义,如 < 使用转义字符串 &lt; 代替。

CSRF: 跨站伪装请求攻击

在用户已登录的情况下,伪装用户的身份发起请求,进行相关攻击。解决方式,确认用户的身份。比较好理解的解决方式是: 二次确认,通过用户的二次确认确认请求方为真实用户。然后就是 X-Requested-With 请求标志,通过该请求头设置标志位 ajax 请求,可以一定程度阻止跨域的伪装。Anti-CSRF TOKEN 方案:通过服务端与客户端唯一的 token 值进行校验,可以看做一个暗号,让别人无法伪装!

网络劫持

Jsonp 劫持

我们都知道 jsonp 就是为了解决跨域的,如果传输信息设计到比较敏感的数据,那么别人可以很方便调用你的接口,获取你的数据,存储在自己的数据库中。解决方法,添加脚本可运行白名单,不要传输敏感信息。

HTTP 劫持。

HTTP 是明文传输,所以运营商可以知道你的代码是什么,然后在里面加一点小广告什么的,改变你的内容。解决方法就是使用 https 协议,可耻的运营商

DNS 劫持

通过域名解析我们才能找到对域名的服务器 ip 地址,劫持了 DNS 就可以给你返回一个错误的 ip 地址。在 dns 解析中,会先在本机搜索域名解析记录,无相关记录像 dns 服务商发起请求。所以要么你本地信息被篡改,要么服务商欺骗你。 转一篇 DNS 劫持详解链接

接口安全

数据库

数据库,插入数据库的参数,在执行 sql 的时候小心它把你整个数据库表给删了。这里的攻击类似 xss 攻击,通过传输、拼接一些字符串改变原本的 sql 语义

推送消息

比如短信发送消息,非常的有代表性。通过接口的参数传递,以及最后的发送内容,可以推测出你的推送内容的组合相关方式,就可以通过不良参数,很方便的发送的一些不合法的信息,或有毒链接给用户。解决方式就是不要相信用户传入的任何参数,对参数进行校验,发送内容尽量可选择匹配模式,如 code 值映射,对不合法的参数才有默认内容发送。

DDOS:分布式拒绝服务

就是很多请求大量涌入你的服务器,导致它们都没有空闲可以响应真正的用户请求。通过 TCP 连接,我们知道建立连接需要三次确认,一般攻击者可以伪造 ip, 发起大量连接请求,却又不确认 = = 导致服务器白白等待直到超时。其次可以借用别的用户,在一个大流量用户网站地方的某一个页面上了,通过 xss 默认发起对攻击网站的请求,并发送很大的数据,但每次发送很少的字节,这些用户就被当成了肉鸡,然后使其瘫痪。解决防范:增加机器, 对同一个ip 的过多请求进行防范。

',21)]))}]])}}]); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNjU4LmJ1bmRsZS5qcyIsIm1hcHBpbmdzIjoiNktBQWVBLE1BQU0sa0JDQ2ZDLEVBQVMsQ0FBQyxFQUtoQixPQUZpQyxFLE9BQUEsR0FBZ0JBLEVBQVEsQ0FBQyxDQUFDLFMsZ0NESmpEQyxFQUFBQSxFQUFBQSxJQXlCSixNQXpCSUMsRUF5QkpDLEVBQUEsS0FBQUEsRUFBQSxLQXpCTkMsRUFBQUEsRUFBQUEsSUFBQSx3bkQiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9jYm95LWJsb2cvLi4vLi4vYmxvZ3MvbWFya2Rvd24vc2FmZS5tZCI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NDIzOGVjXCI+6L2s5LiA56+HIEROUyDliqvmjIHor6bop6Ppk77mjqU8L2E+PC9wPlxuPGgyPuaOpeWPo+WuieWFqDwvaDI+XG48aDM+5pWw5o2u5bqTPC9oMz5cbjxwPuaVsOaNruW6k++8jOaPkuWFpeaVsOaNruW6k+eahOWPguaVsO+8jOWcqOaJp+ihjCBzcWwg55qE5pe25YCZ5bCP5b+D5a6D5oqK5L2g5pW05Liq5pWw5o2u5bqT6KGo57uZ5Yig5LqG44CC6L+Z6YeM55qE5pS75Ye757G75Ly8IDxjb2RlPnhzczwvY29kZT4g5pS75Ye777yM6YCa6L+H5Lyg6L6T44CB5ou85o6l5LiA5Lqb5a2X56ym5Liy5pS55Y+Y5Y6f5pys55qEIHNxbCDor63kuYk8L3A+XG48aDM+5o6o6YCB5raI5oGvPC9oMz5cbjxwPuavlOWmguefreS/oeWPkemAgea2iOaBr++8jOmdnuW4uOeahOacieS7o+ihqOaAp+OAgumAmui/h+aOpeWPo+eahOWPguaVsOS8oOmAku+8jOS7peWPiuacgOWQjueahOWPkemAgeWGheWuue+8jOWPr+S7peaOqOa1i+WHuuS9oOeahOaOqOmAgeWGheWuueeahOe7hOWQiOebuOWFs+aWueW8j++8jOWwseWPr+S7pemAmui/h+S4jeiJr+WPguaVsO+8jOW+iOaWueS+v+eahOWPkemAgeeahOS4gOS6m+S4jeWQiOazleeahOS/oeaBr++8jOaIluacieavkumTvuaOpee7meeUqOaIt+OAguino+WGs+aWueW8j+WwseaYr+S4jeimgeebuOS/oeeUqOaIt+S8oOWFpeeahOS7u+S9leWPguaVsO+8jOWvueWPguaVsOi/m+ihjOagoemqjO+8jOWPkemAgeWGheWuueWwvemHj+WPr+mAieaLqeWMuemFjeaooeW8j++8jOWmgiBjb2RlIOWAvOaYoOWwhO+8jOWvueS4jeWQiOazleeahOWPguaVsOaJjeaciem7mOiupOWGheWuueWPkemAgeOAgjwvcD5cbjxoMj5ERE9T77ya5YiG5biD5byP5ouS57ud5pyN5Yqh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NC4yX0B2dWUrY29tcGlsZXItc2ZjQDMuNS4zX3Z1ZUAzLjUuM190eXBlc2NyaXB0QDUuNS40X193ZWJwYWNrQDUuOTQuMF93ZWJwYWNrLV9mdXFrd2dncGxoZXkzb2l2dHdlMnN0ZG82ZS9ub2RlX21vZHVsZXMvdnVlLWxvYWRlci9kaXN0L2V4cG9ydEhlbHBlci5qc1wiXG5jb25zdCBfX2V4cG9ydHNfXyA9IC8qI19fUFVSRV9fKi9leHBvcnRDb21wb25lbnQoc2NyaXB0LCBbWydyZW5kZXInLHJlbmRlcl1dKVxuXG5leHBvcnQgZGVmYXVsdCBfX2V4cG9ydHNfXyJdLCJuYW1lcyI6WyJjbGFzcyIsInNjcmlwdCIsIl9jcmVhdGVFbGVtZW50QmxvY2siLCJfaG9pc3RlZF8xIiwiX2NhY2hlIiwiX2NyZWF0ZVN0YXRpY1ZOb2RlIl0sInNvdXJjZVJvb3QiOiIifQ== \ No newline at end of file diff --git a/707.bundle.js b/707.bundle.js new file mode 100644 index 0000000..4c09e75 --- /dev/null +++ b/707.bundle.js @@ -0,0 +1,2 @@ +"use strict";(self.webpackChunkreact_wyz=self.webpackChunkreact_wyz||[]).push([[707],{707:(n,e,t)=>{t.r(e),t.d(e,{default:()=>o});const o="当我们要完成一个应用的时候,会根据对应的功能划分为许多不同的模块,就像一个论坛,有发帖的模块,评论的模块,js 中的模块也正是如此,一个具体功能的代码抽成一个文件,当你做一个东西的时候需要用到这个功能的时,可以直接使用这个文件,实现功能的分离,并能在多个需要的地方使用。就像是螺丝钉、螺丝帽、垫片一样的,通过组合使用实现出你的产品。\n\n通过直白的描述,我们可以知道,模块化的好处就是,抽离代码,重复使用,如现在很直观的代表 npm 包。\n\n\n\n那么模块化到底是怎么实现的呢?\n\n先来了解一下历史,以前的 html 不知道大家还记不记的, 一个html 页面引入了多个 js 文件.\n```\n\n\n\n \n So UI - A Component Library for Vue.js.\n\n\n
\n
\ No newline at end of file diff --git a/post-github.sh b/post-github.sh index c48f4d2..2b24853 100755 --- a/post-github.sh +++ b/post-github.sh @@ -1,38 +1,42 @@ #!/bin/bash -npm run build +# npm run build -output_dir="./build_file" -rm -rf $output_dir -mkdir $output_dir -search_dir="./packages/" +# output_dir="./build_file" +# rm -rf $output_dir +# mkdir $output_dir +# search_dir="./packages/" -for package in `ls $search_dir`; do - package_dist="$search_dir$package/dist/"; - cp -r $package_dist $output_dir -done +# for package in `ls $search_dir`; do +# package_dist="$search_dir$package/dist/"; +# cp -r $package_dist $output_dir +# done -git stash -git branch -D gh-pages -git fetch -p -git checkout -b gh-pages origin/gh-pages +# git stash +# git branch -D gh-pages +# git fetch -p +# git checkout -b gh-pages origin/gh-pages -for file in ./*; do - # echo $file; - if [[ "$file" != "./post-github.sh" && - "$file" != "./build_file" && - "$file" != "./packages" && - "$file" != "./node_modules" - ]]; then - rm -r "$file" - fi -done +# for file in ./*; do +# # echo $file; +# if [[ "$file" != "./post-github.sh" && +# "$file" != "./build_file" && +# "$file" != "./packages" && +# "$file" != "./node_modules" +# ]]; then +# rm -r "$file" +# fi +# done -mv $output_dir/* ./ -rm -rf $output_dir \ No newline at end of file +# mv $output_dir/* ./ +# rm -rf $output_dir + +git add . +git commit -m "feat: update blog" +git push origin gh-pages \ No newline at end of file