npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

patch-vue3

v0.0.54

Published

一个基于webpack的vue3补丁。用于将vue2相关语法转换到vue3

Downloads

9

Readme

patch-vue3

一个基于webpack的vue3补丁。用于将vue2相关语法转换到vue3

注意事项

  • 仅兼容转换在vue3中废弃或不支持的语法

  • 不支持非.vue文件中的相关语法转换

  • 不支持jsx写法转换(即options API中配置的render函数)

  • 不支持在beforeCreate中使用的eventBus,因为patch-vue3会将其注入到methods中,针对此类情况可自行在全局挂载

安装与使用

// 安装
npm install patch-vue3 -D
// 使用
const PatchVue3 = require('patch-vue3').default;
// 在webpack的plugins中调用
new PatchVue3(PatchVue3Options)

参数

interface PatchVue3Options {
  identifier?: {
    // ui库
    uiLib?: string;
    // render函数渲染的ui组件
    uiComponents?: string[];
    // 挂载的eventBus名称,默认值为'$bus'
    eventBus?: string;
    // 挂载的$children名称,默认值为'$children'
    mountChildren?: string;
  };
  config?: {
    // ui库的前缀,比如element的el-、iview的i-
    uiLibPrefix?:string;
    // eventBus的引用路径,默认引入路径为webpack配置的别名key+‘/util/patch’,该模块需要导出名称为bus的对象
    busImportPath?: string;
    // 是否启用别名,启用后,查找并应用webpack配置项中的第number个alias key,默认为0,指定-1关闭
    alias?: number;
    // 当非setup标签、非setup函数、非jsx render、非多根节点时,又想要sfc文件跳过本插件处理时指定,默认为refuse-patch
    skipTag?: string;
    // prettier配置文件地址,默认为根目录下的.prettierrc
    prettierrc?: string;
    // 全局过滤器,当前sfc找不到filter配置时降级使用
    globalFilters?: string[];
    // 是否校验props,默认true
    validateProps?:boolean;
    // 当某个文件被跳过时,是否输出日志,默认为false
    printWhenSkip?:boolean;
  };
  /**
   * hooks有两种调用方式
   * 当在回调函数内部访问了外部变量时需要使用对象形式(该变量必须静态)
   * e.g
   *  "patch:start":{
   *    context:{
   *     id:'spp'
   *    },
   *    callback:(id, code) => {
   *      console.log(this.id)
   *    }
   *  }
  */
  hooks?: {
    // 文件开始被处理时的回调
    "patch:start"?: (id: string, ctx: {
      getSource: () => string;
    }) => undefined | string;
    // 文件处理完成时的回调
    "patch:end"?: (id: string, code: {
      getSource: () => string;
    }) => undefined | string;
    // 处理script时的回调,必须显式调用ctx.save或ctx.giveUp方法
    "patch:scriptNode"?: (node: AstNode, ctx: ScriptCtx) => void;
    // 处理template时的回调
    "patch:templateNode"?: (node: AstNode, ctx: TemplateCtx) => void;
  };
}

interface Ctx {
  // 遍历节点
  dfs: (node: AstNode, cb: (node: Node) => void) => void;
  // 模版源码
  getSource: () => string;
  // 保存更新后的源码
  save: (code: string) => void;
  // 文件id
  id:string;
  // 传参在不同hook间使用
  inject:(data:any)=>void;
}

interface ScriptCtx & Ctx {
    // 获取某一段script code
    loadScript:(code:string,start:number,flag:[string,string])=>string;
}

interface TemplateCtx & Ctx {
  // 获取tag标签
  loadTag: (
    code: string,
    attr: string,
    config?: {
      lastIndex: number;
      tagName: string;
    }
  ) => string;
}

即将支持

  • watch.key为数组时强制deep
  • vNode生命周期