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

网站设置搜索框是什么知识点有没有什么做高数的网站

网站设置搜索框是什么知识点,有没有什么做高数的网站,网站流量导入是什么意思,建设企业网站的企业转载自 深入wepy源码#xff1a;wpy文件编译过程wepy 是腾讯开源的一款小程序框架#xff0c;主要通过预编译的手段#xff0c;让开发者采用类 Vue 风格开发。 让我们一起看看#xff0c; wepy 是如何实现预编译的。先放上一张官网的流程图#xff0c;后面的分析可以参考该…转载自 深入wepy源码wpy文件编译过程wepy 是腾讯开源的一款小程序框架主要通过预编译的手段让开发者采用类 Vue 风格开发。 让我们一起看看 wepy 是如何实现预编译的。先放上一张官网的流程图后面的分析可以参考该图。wepy-cli 主要负责 .wpy 文件的编译目录结构如下编译的入口是 src/compile.js 中的 compile() 方法该方法主要是根据文件类型执行不同的 compiler 比如 .wpy 文件会执行 compile-wpy.js 下的 compile() 方法。 compile(opath) {...switch(opath.ext) {  case ext:  cWpy.compile(opath);  break;  case .less:  cStyle.compile(less, opath);  break;  case .sass:  cStyle.compile(sass, opath);  break;  case .scss:  cStyle.compile(scss, opath);  break;  case .js:  cScript.compile(babel, null, js, opath);  break;  case .ts:  cScript.compile(typescript, null, ts, opath);  break;  default:  util.output(拷贝, path.join(opath.dir, opath.base)); ... } }   .wpy文件拆解compile-wpy.js 下的 compile() 方法核心调用了 resolveWpy() 方法。resolveWpy() 方法主要是将 .wpy 拆解成 rst 对象并对其中的 template、script 做一些预处理然后将 template、 script、 style 三部分移交给不同的 compiler 处理。 生成rst对象 通过 xmldom 获取 xml 对象然后遍历节点拆解为 rst对象。 import {DOMParser} from xmldom; export default {createParser (opath) {return new DOMParser({...})},...resolveWpy () {let xml this.createParser(opath).parseFromString(content);} } rst对象结构如下 let rst {moduleId: moduleId,style: [],template: {code: ,src: ,type: },script: {code: ,src: ,type: } }; 此外还对 template 做了如下一些预处理获取文件中的 import 放入 rst.template.components 中获取 props 和 events 放入 rst.script.code 中 compile-template compile-template.js 中的 compile() 方法根据 template 的 lang 值执行不同的 compiler 比如 wepy-compile-typescript 。编译完成后执行 compileXML 方法做了如下的操作 updateSlot 方法: 替换 slot 内容updateBind 方法: 在 {{}} 和 attr 上加入组件的前缀例如 {{width}} - {{$ComponentName$width}}把自定义的标签、指令转换为 wxml 语法例如 repeat forxxx indexidx itemxxx keyxxx/repeat !-- 转换为 -- block wx:forxxx wx:for-indexxxx wx:for-itemxxx wx:keyxxxx/block compile-style 依旧先是根据 lang 值先执行不同的 compiler 比如 wepy-compile-less 。编译完成后执行 src/style-compiler/scope.js 中的 scopedHandler() 方法处理 scoped。 import postcss from postcss; import scopeId from ./scope-id;export default function scopedHandler (id, content) {console.log(id is: , id)console.log(css content is: , content)return postcss([scopeId(id)]).process(content).then(function (result) {console.log(css result is: , result.css)return result.css}).catch((e) {return Promise.reject(e)}) } 这里主要是利用 add-id 的 postcss 插件插件源码可参考 src/style-compiler/scope-id.js。根据上面的代码打印出来的log如下最后会把 requires 由绝对路径替换为相对路径并在 wxss 中引入最终生成的 wxss 文件为 import ./../components/demo.wxss;Page{background:#F4F5F7} ...   compile-script 依旧先是根据 lang 值执行不同的 compiler。compiler 执行完之后判断是否是 npm 包如果不是依据不同的 type 类型加入 wepy 初始化的代码。 if (type ! npm) {if (type page || type app) {code code.replace(/exports\.default\s*\s*(\w);/ig, function (m, defaultExport) {if (defaultExport undefined) {return ;}if (type page) {let pagePath path.join(path.relative(appPath.dir, opath.dir), opath.name).replace(/\\/ig, /);return \nPage(require(wepy).default.$createPage(${defaultExport} , ${pagePath}));\n;} else {appPath opath;let appConfig JSON.stringify(config.appConfig || {});let appCode \nApp(require(wepy).default.$createApp(${defaultExport}, ${appConfig}));\n;if (config.cliLogs) {appCode require(\./_wepylogs.js\)\n;}return appCode;}});} } 接下来会执行 resolveDeps() 方法主要是处理 requires。根据 require 文件的类型拷贝至对应的目录再把 code 中的 require 代码替换为 相对路径。 处理好的 code 最终会写入 js 文件中文件存储路径会判断类型是否为 npm。 let target; if (type ! npm) {target util.getDistPath(opath, js); } else {code this.npmHack(opath, code);target path.join(npmPath, path.relative(opath.npm.modulePath, path.join(opath.dir, opath.base))); } plugin 根据上面的流程图可以看出所有的文件生成之前都会经过 Plugin 处理。先来看一下compiler 中是如何载入 Plugin 的。 let plg new loader.PluginHelper(config.plugins, {type: css,code: allContent,file: target,output (p) {util.output(p.action, p.file);},done (rst) {util.output(写入, rst.file);util.writeFile(target, rst.code);} }); 其中config.plugins 就是在 wepy.config.js 中定义的 plugins。让我们来看一下 PluginHelper 类是如何定义的。 class PluginHelper {constructor (plugins, op) {this.applyPlugin(0, op);return true;}applyPlugin (index, op) {let plg loadedPlugins[index];if (!plg) {op.done op.done(op);} else {op.next () {this.applyPlugin(index 1, op);};op.catch () {op.error op.error(op);};if (plg)plg.apply(op);}} } 在有多个插件的时候不断的调用 next()最后执行 done()。 编写plugin wxss 与 css 相比拓展了尺寸单位即引入了 rpx 单位。但是设计童鞋给到的设计稿单位一般为 px那现在我们就一起来编写一个可以将 px 转换为 rpx 的 wepy plugin。 从 PluginHelper 类的定义可以看出是调用了 plugin 中的 apply() 方法。另外只有 .wxss 中的 rpx 才需要转换所以会加一层判断如果不是 wxss 文件接着执行下一个 plugin。 rpx 转换为 px 的核心是使用了 postcss-px2units plugin。下面就是设计好的 wepy-plugin-px2units更多源码可参考 github 地址( https://github.com/yingye/wepy-plugin-px2units )。 import postcss from postcss; import px2units from postcss-px2units;export default class {constructor(c {}) {const def {filter: new RegExp(\.(wxss)$),config: {}};this.setting Object.assign({}, def, c);}apply (op) {let setting this.setting;if (!setting.filter.test(op.file)) {op.next();} else {op.output op.output({action: 变更,file: op.file});let prefixer postcss([ px2units(this.setting.config) ]);prefixer.process(op.code, { from: op.file }).then((result) {op.code result.css;op.next();}).catch(e {op.err e;op.catch();});}} } 最后 本文分析的源码以 wepy-cli1.7.1 版本为准更多信息可参考 wepy github (即 github 1.7.x 分支https://github.com/Tencent/wepy/tree/1.7.x )。另外文中有任何表述不清或不当的地方欢迎大家批评指正。
http://www.yutouwan.com/news/214405/

相关文章:

  • 做网站用哪个软件最好php没备案的网站
  • 建设电影播放网站微网站做的比较好
  • 网站布局类型代理平台哪个好
  • 徐州建站公司模板wap网站如何做
  • 湖南建设网站公司网页设计制作代码大全
  • 想做外贸做哪些网站好wordpress常规选项
  • 建设网站怎么查明细代理注册公司怎么样
  • 顺德网站建设案例咸阳专业网站建设
  • 中网互联网站建设什么职位做网站
  • 哪些动物可以做网站名国内网站建设阿里云
  • 小公司怎样自己建网站wordpress固定链接
  • 免费高清大图网站做电影网站代理合法么
  • 在唐山做网站多少钱云南建投第十建设有限公司网站
  • 网站没收录要怎么做sketch网站花边怎么做
  • h5建设网站竞价推广课程
  • 网站多久被百度收录培训机构在哪个平台找
  • wampserver网站开发步骤海珠网站建设公司
  • asp.net做简易网站网站建设公司有哪些原
  • 河北城乡建设厅网站显示不全西安汽车网站制作
  • 黄冈网站官方登录平台广州网站建设业务
  • 全国可信网站如何做简单网站首页
  • 网站解析后163公司企业邮箱
  • 英文网站建设成都桔子建站官网
  • 网站适配手机成都房建设部网站
  • 咸阳哪里做网站比较好的做外贸网站
  • 济南企业营销型网站建设网络营销的特点包括哪些?
  • 如何给别人做网站挣钱wordpress 要求php版本
  • 公司网站建设解决方案网站推广有哪些常用的方法
  • 桂平网站设计网络运营商架构
  • 做网站首先要干什么建和做网站