# 制作和发布插件指南

DCloud有活跃的插件市场,https://ext.dcloud.net.cn/,并提供了计价销售、广告解锁、赞助、评价等机制。

# 为什么提交插件

  • 写出通用的功能模块时,可以分享给其他有相同需求的人。人人贡献、人人受益。
  • 通过赞赏、广告分成、计费销售,收获物质回报。
  • 通过插件下载量、评星、排行,收获荣誉。

很多优秀的插件作者,可以做到每月销售数万元的插件。(只有uniCloud插件和App原生或uts插件支持付费,其他类型插件不能设价格)

了解插件变现的详细信息,另见文档插件变现

# 插件制作注意

uni插件其实是uni-app项目下一部分代码,但提交时注意:

  • 遵循插件目录规范,其中比较重要的是确定插件ID,详细解释下方。
  • 插件包中不应该包含 unpackage 目录,最好也不包含 node_modules 目录。
  • 插件包中不应该包含版本控制相关文件和目录,如 .git,.svn 等。
  • 前端建议使用scss预处理并引用uni.scss中的变量定义,保持各插件风格统一,方便插件使用者通过搭积木的方式开发整体风格一致的App

插件ID命名规范:

  1. 格式为:'作者ID-插件英文名称',示例:'xiaoming-abc',其中作者ID和插件名称只能包含英文、数字
  2. 作者ID由插件作者自定义,不能使用'DCloud'、'uni'等关键字,长度要求至少2位字符
  3. 插件名称需直观表达插件的作用,例如:eshop、button等

Since HBuilderX 3.1, uni_modules has been added, which is an important modular solution for the uni ecosystem. For details, see: https://uniapp.dcloud.net.cn/uni_modules

uni_modules发布后,建议插件作者首先在自己的项目下建一个uni_modules,在本地开发调试没问题后,对uni_modules下你的插件目录点右键,提交发布到插件市场。

插件市场分多种插件,分类介绍如下:

# 前端组件

前端组件指uni-app前端使用vue/nvue/wxml等技术开发的、用于页面内嵌的组件。它又进一步细分为vue组件、uvue组件、nvue组件、小程序自定义组件。这个分类不包含uts原生组件。

Let's take the tag component developed by Xiaoming (plugin ID: xiaoming-tag) as an example, when uploading the plugin market, the directory structure requirements are as follows:

In order to keep the code concise, only the necessary files and directories need to be included when uploading the plugin.

If the component depends on the third-party components, the three-party components need to be packaged and uploaded together; if "xiaoming-tag" depends on the icon component (xiaohong-icon) developed by Xiaohong, when publishing the "xiaoming-tag" plugin, the directory structure requirements are as follows:

Tips:

  • Common components, nvue components, and directory structure requirements are the same
  • 小程序组件的一级目录,名字需从 components 变更为 wxcomponents ,其它结构要求相同
  • 组件不能包含根目录的 manifest.json、pages.json、App.vue、main.js 等文件

# 付费前端插件

插件市场很早就支持原生插件和uniCloud云插件的加密保护。但前端插件,比如ui库,尤其是可编译到web和小程序的插件,由于其载体的特殊开放性,很难做知识产权保护。

HBuilderX 4.19起,DCloud提供了一种云编译的手段来解决前端插件的知识产权保护问题。

插件作者设置加密后,插件使用者下载到的插件是加密后的版本。在运行、发行对前端代码编译时,uni-app x的编译器会将加密插件发送到DCloud的云编译服务器进行编译,将编译结果混入本地编译工程。从而实现插件使用者可以使用插件但无法获取插件源码的效果。这种云编译仅在第一次进行,云编译一次后会有缓存。

当然插件使用者可以获取到编译后的代码,但就像uni-app (x)编译后的代码非常难懂,更不会有人去改一样,这种方式虽然不严谨但大体上还是有效保护的了前端插件作者的知识产权。

这个过程不会把插件使用者的项目源码整体发送到DCloud服务器,云编译和解密的仅包括加密插件。

插件市场所有加密付费的插件,均有普通授权和源码授权两种版本。如果购买了源码授权,插件作者可以得到插件的完整源码,此时不再发送插件源码到云编译服务器。

不管是普通授权版还是源码授权版,都是绑定唯一的appid和包名。如购买者更换了这2个信息中的一个,需要重新购买授权。注意参考插件购买协议。

通过开发工具、编译器、运行时的整体配合,DCloud给前端插件作者提供了以往不存在的、更为优秀的知识产权保护方案。包括源码授权版,DCloud也会检查盗版行为。

目前前端插件加密,仅支持uni-app x下uni_modules形式的、符合 easycom 规范的组件。插件可在全平台加密,包括web端、app端。

如需发布付费插件,可对插件设置普通授权版源码授权版的价格。DCloud插件市场会自动加密付费插件中所有vue、uvue、uts、js、ts文件(除pages、hybrid、static目录外)

HBuilderX发布插件界面暂未支持前端组件价格设置,插件作者可在插件package.json中手动配置价格后提交发布,后续ui上将支持前端组件价格设置。 配置方式参考uni_modules配置,在package.jsondcloudext下添加sale销售信息。

前端组件付费插件支持试用,当插件用户试用插件时,无法查阅这些加密的源码。插件试用只能用于本地运行或打包自定义基座,不能用于正式发布。

如果插件用户购买了普通授权版,也看不到这些加密文件的源码,运行或打包时,会提交到云端进行验证、解密及编译。

前端组件付费插件开发注意事项:

  • 目前仅支持uni-app x项目,不支持uni-app项目,且最低需要HBuilderX 4.19+
  • 不支持混搭utssdk目录、不支持页面加密、仅支持符合 easycom 规范的组件。可通过依赖的方式配置其他插件(目前仅支持依赖同样加密的插件)。
  • 插件需要对外导出方法、类型等内容时,需要在插件根目录 index.uts 做导出,使用者不能直接引入插件内部的文件
  • 加密组件属性的代码提示配置在发布时云端会自动生成,点此查看配置说明
  • 前端组件付费插件使用时会单独上传至云端独立编译(此时不会包含项目内的其他内容),所以插件不能引入项目内其他目录资源,此类需求,可以通过API让插件使用者传入对应的数据
  • app-android 平台,不支持导出 vue 的 plugin 和 mixin

前端组件付费插件使用注意事项:

  • 当项目包含前端付费插件时,首次运行或发行到指定平台时,会触发付费插件在该平台的云端编译,此时需要您的电脑处于联网状态,且您登录的HBuilderX账号需要具备使用该插件的权限(购买、试用、协作等),一旦云端编译成功,后续将使用本地缓存,如果更新了的插件版本、HBuilderX版本或运行时勾选了清除缓存,会再次触发云端编译。

  • 不支持直接引入插件内部的文件,仅支持导入插件根目录

    • 正确的引入方式:import { test } from '@/uni_modules/test-components' // 需要插件作者在 index.uts 中 导出 test
    • 错误的引入方式:import { test } from '@/uni_modules/test-components/test.uts'

# uni-app front-end template

# vue/nvue page template

Let's take the setting template (xiaoming-setting) developed by Xiaoming as an example. When uploading the plugin market, the directory structure requirements are as follows:

当然依赖管理,可以使用uni_modules,在你的uni_modules目录下的package.json中配置依赖另一个uni_modules,此时就不用再包含其他插件的源码,但这种做法无法锁定版本,会在使用者下载你的插件时自动安装最新的依赖。

如果你的页面,需要在下载时被注册到使用者的项目的pages.json中,从HBuilderX 3.5.0+ 插件导入工程时,支持合并页面路由到项目的 pages.json。详见

Tips:

  • Vue page template and nvue page template directory structure requirements are the same.
  • When packaging a page template, you need to include manifest.json, pages.json and other files.

# uni-app front-end project template

Tips:

  • The unpackage directory does not need to be included when the project template is packaged;
  • 项目模板打包时需要包含 manifest.json 文件。manifest.json 里不允许有 appid,包括 DCloud appid 或微信等三方 appid;
  • 如果模板中包含 uniCloud 相关的云函数目录,如 uniCloud-aliyun、uniCloud-tcb,请选择“uniCloud”->“前后一体项目模板”。如果不使用云函数功能,则应该从插件包中删除 uniCloud 相关目录。

# JS SDK

When developing the JS SDK, there is no special requirement for the directory structure, just name the js file as the plugin ID, for example: xiaoming-md5.js

Tips:

  • Cannot include manifest.json, pages.json, App.vue, main.js and other files in the root directory

如果是非uni_modules的js sdk,使用者下载后会被下载到使用者项目根目录下的js_sdk目录

# UTS插件

uts插件开发详见插件开发文档,这里主要说明uts付费插件发布的注意事项。

uts付费插件分为普通授权版源码授权版,两种付费方式区别详见说明文档

如需发布付费插件,可对插件设置普通授权版源码授权版的价格。DCloud插件市场会对付费插件自动加密,付费插件加密规则:

  • 加密除 interface.uts 之外的所有uts文件
  • 加密utssdk/app-android及utssdk/app-ios目录下的java、kt、swift等混编文件

当插件用户试用插件时,无法查阅这些加密的源码。uts插件试用只能用于打包自定义基座,不能用于正式发布。

如果插件用户购买了普通授权版,也看不到这些加密文件的源码,提交云打包时,会在云端验证并解密文件进行打包。

如果插件作者上传插件时,设置了提供源码授权版,且插件使用者购买了源码授权版,才能下载到插件的源码。

不管是普通授权版还是源码授权版,都是绑定唯一的appid和包名。如购买者更换了这2个信息中的一个,需要重新购买授权。

Tips:

  • uts加密插件只支持云端传统打包,不支持离线打包、也不支持安心打包。打包最低需要HBuilderX 3.7.2+
  • 一般提交的uts插件仅包含uts源码,不建议包含三方sdk,如jar,这些应该配成仓储。

# uts插件和App原生语言插件的区别

uts插件和App原生插件在功能上是重叠的,都是原生扩展uni-app的能力。

从uts插件发布后,DCloud建议插件作者开发uts插件,替代老的原生插件。

它们之间有如下具体差别:

  • uts开发和使用更加简单、清晰、小巧
  • uts插件更新免审核,无需等待DCloud管理员审核上架
  • uts插件天然支持多版本,插件作者更新后,使用者可以不更新,可以仍然使用之前下载到本地的老版插件
  • uts插件支持源码版计费,可以卖更高的价格,相关版权由DCloud进行保护,防止盗版和侵权。并且很多使用者确实有源码需求,担心三方SDK有不可控的代码。

目前uni-app的ext api全部基于uts实现,一些内置api如弹框也已经改成uts实现。虽然对于开发者而言这些并非需要下载的插件,但其实本质是内置于runtime的uts插件。未来uni-app的所有官方api都会改为uts实现。uts的开发体验会优化到最佳。而原生语言插件只会修改较严重的bug。

在未来,uts插件将同时支持下一代的uni-app的uvue,以及现有的vue、nvue。而app原生语言插件只支持这一代的uni-app,无法支持uvue。

包括uts组件,也将支持vue页面。而原生语言插件的组件模式不会支持vue页面,只支持nvue页面。

注意uts插件目前还不支持离线打包,不过插件市场销售的原生语言插件也不支持离线打包。建议有个性化打包需求的开发者使用HBuilderX的cli来处理自动化打包。

FAQ:

  • 为什么原生插件需要审核,且很慢,而uts插件免审核? 因为uts插件,提交的是源码,可控。而原生插件提交给DCloud的是编译后的文件,需要人工审核。实际上uniCloud插件也是免审核的,也是同样的代码,只有提交的是源码,都是免审的。

# App原生语言插件

App原生语言插件,需使用Andorid/iOS原生环境开发实现,请参考以下教程:

Compressed package format requirements: After opening the zip, the root directory must be the plugin id directory, and the secondary directory is the ios, android subdirectory and package.json. For details, refer to [uni native plugin package format](https://nativesupport.dcloud.net. cn/NativePlugin/course/package)

从uts插件发布后,DCloud建议插件作者开发uts插件,替代老的原生插件。原因见上

# HBuilderX插件

The HBuilderX plugin is installed in the HBuilderX tool. It is a plug-in for the editor, not a plug-in for the mobile app. For detailed development tutorials, see: http://hx.dcloud.net.cn/

# uniCloud

# Cloud function template

Cloud function templates have no special requirements for file naming, but when creating a plug-in zip package, you need to pay attention to the following points:

  • When the template contains one or more cloud functions, you cannot just put the cloud function directory in the plug-in, but need to start from the project root directory completely. Such as uniCloud/cloudfunctions/cf123. uniCloud can accept -aliyun or -tcb suffix (the two directories of Aliyun and Tencent Cloud can also exist at the same time);
  • 云函数有效的入口文件为 index.js,插件包中必须包含至少一个以此命名的文件。
  • 涉及账户管理的话,请使用uni-id

If you upload a paid cloud function plugin, you must select the cloud function you want to encrypt, otherwise plugin trial users can use your plugin indefinitely through the trial process without paying.

Define the encrypted cloud function. In order to unify the standard with uni_modules and discard the original encryptlist.json, you need to add package.json to the root directory of the plugin, and configure the files to be encrypted in uni_modules->encrypt, such as:

{
	"uni_modules": {
			"uniCloud-aliyun/cloudfunctions/function/index.js"
		],
	}
}

The js files of cloud functions and public modules under uniCloud/cloudfunctions can be flexibly configured in the encrypt array, which is more flexible than configuring the entire cloud function or public module in the original encryptlist.json file.

After defining the cloud function content to be encrypted, upload the plug-in, and the DCloud plug-in market will automatically encrypt these cloud functions. When the plug-in user tries the plug-in, he cannot view the source code of these cloud functions, and only during the trial period (usually 7 days), these encrypted cloud functions can be run on the service space he deployed. After the trial period, these cloud functions will be Automatically lapse.

Even if the plug-in user purchases the normal authorized version of the plug-in, he cannot see the source code of these encrypted cloud functions, but these cloud functions can run normally on the service space bound when he purchased them. and cannot be uploaded to other service spaces.

If the author of the plug-in uploads the plug-in, and the authorized version of the source code is provided at the same time, and the user of the plug-in has purchased the authorized version of the source code, all the source code of the plug-in can be obtained.

For the difference between the ordinary authorized version and the source code authorized version, please refer to: https://ask.dcloud.net.cn/article/38040

Starting from HBuilderX 3.2.0, when a paid plug-in for cloud-integrated project template or cloud-integrated page template is released, the front-end js file also supports encryption. The setting method is similar to the cloud function. Define the file path in uni_modules->encrypt, like:

{
	"uni_modules": {
		"encrypt": [
			"js_sdk/index.js",
			"components/demo/demo.js"
		],
	}
}

目前只支持付费插件的js文件加密,vue及nvue文件无法加密,业务核心逻辑建议写到js中。 如果发布云端一体项目且包含uni_modules时,则不会加密uni_modules目录下的文件,uni_modules下应该做为独立插件发布,分别进行加密配置。

If your plugin configuration contains confidential information, you want to protect these configurations from uploading. Reference: uni_modules plugin upload auxiliary script example

# Cloud integrated page template

Cloud integrated page template, if not uni_modules, it is a single-page template, and only one page can be placed. In the case of uni_modules, any number of pages can be placed.

In order to prevent conflicts with the existing code of the project when importing, pay attention to the following naming conventions:

  • Must include cloud function related directories (uniCloud/cloudfunctions), can include js_sdk, pages, components, static and other directories
  • The name of cloud functions and public modules needs to contain "-", that is, there is a plugin ID prefix.
  • Subdirectories and file names under js_sdk, components, static and other directories need to contain "-"
  • Cannot include manifest.json, App.vue, main.js and other files in the root directory
  • 如需注册页面到项目的pages.json中,参考uni_modules文档

# Front and back project template

It is basically the same as the uni-app front-end project template directory structure, but must include uniCloud related directories (uniCloud-aliyun, uniCloud-tcb)

# uniCloud admin plugin

After using the uniCloud admin basic framework, you can further integrate the admin plugin written by the plugin author to enrich the functions of your own admin system. Plugin authors can also submit plugins according to this document, and select Admin Plugins in the uniCloud category on the upload and release page of the Plugin Marketplace.

因文档较长,请单独参阅:uniCloud admin插件开发指南

# DB Schema and validation functions

It is mainly used to submit data table schema and verification function, so it must include uniCloud-aliyun/database or uniCloud-tcb/database directory

# pages_init

Documentation migrated to uni_modules documentation

# Notice

  • uni-app原生SDK及web项目两个分类下插件发布后需要审核才会生效。
  • 插件不能自行下架,如需下架请发邮件到service@dcloud.io。您也可以把插件标题改为“已废弃”,DCloud管理员会及时审核处理。

如果是非uni_modules插件,那么自己压缩的压缩包注意为标准zip格式,不要使用非主流的压缩软件、不要把rar等其他格式文件的后缀名改名为zip