

uni_modules
is the plug-in modular specification of uni-app (supported by HBuilderRX 3.1.0+), which is usually the encapsulation of a group of js sdk, components, pages, uniCloud cloud functions, public modules, etc. It is used for embedding in uni-app projects, and also supports direct encapsulation as project templates.
Plug-in developers can write a uni_modules
plug-in just like developing a uni-app project, and upload it directly to the plug-in market (opens new window) in HBuilderX.
Plug-in users can find the uni_modules
plugin that meets their needs in Plugin Market (opens new window), and use HBuilderX 3.1.0+ to directly import it into their uni-app project. You can also directly right-click in HBuilderX to upgrade the plug-in later.
Compared with ordinary plug-ins, the uni_modules
plug-in has stronger independence and independent directory structure, and can be released, updated and uninstalled more conveniently (HBuilderX 3.1.0+ provides a right-click menu for the uni_modules
plug-in, and supports publishing, updating, installation dependency, etc.)
Compared with node_modules (node.js module), the third party dependency of uni_modules
defaults to the latest version during installation. Plug-ins are directly installed in the uni_modules
directory without nesting. Of course, if developers want to fix a version of dependencies, they can include the third-party dependencies in their plug-in packages.
Why do we need to invent another uni_modules
wheel after having node_modules
?
node_modules
does not meet the needs of cloud integration. UniCloud's cloud functions, public modules, schema and various js_sdk, components, pages and projects in the front end cannot be effectively integrated in the node_modules
mode.uni_modules
is provided in the form of paid and commercial plug-ins, and the DCloud plug-in market provides copyright protection. But node_modules
does not support payment and copyright protection.node_modules
is a developer-friendly mode that affects the performance of end users. To save trouble, developers nested node_modules
layer by layer, resulting in an astonishing number of files. uni_modules
Module nesting is not supported, and developers are encouraged to optimize package’s sizeuni_modules
encourages developers to always use the latest version. And tools for version content comparison are provided in HBuilderXnode_modules
placing is also supported in uni_modules
, without forced rejection.What are the advantages of uni_modules
compared with ordinary plugins in the plugin market?
If the uni_modules
plugin is a project type plugin, you only need to put a package.json that conforms to the uni_modules
specification in the root directory of the project.
If it is a plug-in of non-project type, such as component, js sdk, page template and cloud function, it needs to be placed in the uni_modules
directory of the project.
At this time, the directory structure under the uni_modules
directory is the same as the project structure of uni-app, as follows:
uni_modules ...
// ...
└── [plugin_id]
├── uniCloud ...
├── components ...
├── hybrid ...
├── pages ...
├── static ...
├── license.md ...
├── package.json ...
├── readme.md ...
├── changelog.md ...
├── menu.json ...
Tips
package.json must exist in every uni_modules
plug-in and contains the basic information of plug-ins. The following is a detailed configuration description of package.json
{
//Note that you cannot directly copy this code into the editor, and package.json currently does not support comments. The comments added in this paragraph are only used to explain the code.
//Required, plug-in ID, in the format: 'Author ID - English name of plug-in', for example: 'xx-yy', where the author ID and plug-in name can only contain English and numbers. Author ID cannot use 'DCloud', 'uni' and other keywords
"id": "Author ID - English name of plug-in",
// Required, used to display the displayed name in the plug-in market
"displayName": "Displayed name of plug-in",
// Required, plug-in version
"version": "1.0.0",
// Required, plug-in description
"description": "Plug-in description",
//Required, keywords of plug-in tag, up to 5
"keywords": [],
// Repository address
"repository": "github:user/repo",
//HBuilderX/cli minimum compatible version
"engines": {
"HBuilderX": "^3.1.0"
},
//DCloud plug-in market configuration
"dcloudext": {
// Required, plug-in market classification
"category": ["Front-end component", "Universal component "],
//Sale (currently only uniCloud plug-ins)
"sale": {
//Price of ordinary authorized version, in yuan. If it is a free plug-in, set the price of ordinary authorized version to 0.
"regular": {
"price": "0.00"
},
//Price of source code authorized version, in yuan
"sourcecode": {
"price": "0.00"
}
},
//QQ numbers of the plug-in author, which facilitates the communication between the administrator and the author when reviewing.
"contact": {
"qq": ""
},
//Privacy, permissions and commercialization statement
"declaration": {
//Required. Whether the plug-in contains advertisements. If so, please fill in the advertising expression and display frequency in detail; if not, please fill in "None
"ads": "",
//Required. Please truthfully fill in the data collected by this plug-in, the sent server address, and the description of the purpose of the data. If no data is collected, please fill in "The plug-in does not collect any data". If the third-party SDK used needs to collect data, please fill in "XX SDK used by the plug-in will collect data. For details, please refer to https://other-sdk.com/
"data": "",
//Required. The list of system permissions that this plug-in needs to apply for, please fill in truthfully. If you need no permission, please fill in "None
"permissions": ""
},
//npm address
"npmurl":""
},
//uni_modules configuration
"uni_modules": {
//List of dependent uni_modules plug-in ID
"dependencies": [],
//Configure cloud function, public module, clientDB Action encryption
"encrypt": [
// Note that this is the real file path. uniCloud under uni_modules does not have -aliyun or -tcb suffix, but unicloud under the root directory of the project has suffix
"uniCloud/cloudfunctions/uni-admin/controller/permission.js"
],
//Platform compatibility: y means Yes, supported; n means No, not supported; u means Unknown, uncertain; The default is u.
"platforms": {
//Cloud platform compatibility
"cloud": {
"tcb": "y",
"aliyun": "y"
},
//Front-end platform compatibility
"client": {
"App": {
"app-vue": "y",
"app-nvue": "n"
},
"H5-mobile": {
//Configure minVersion when you need to specify a minimum version to support it
"Safari": {
"minVersion": "14.0.2"
},
"Android Browser": "y",
"WeChat browser (Android)": "u",
"QQ browser (Android)": "u"
},
"H5-pc": {
"Chrome": "y",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
}
}
}
}
}
Tips
uni_modules.config.json
In the root directory of the project, you can configure the trigger script updated by the plug-in (usually used to perform customized automation tasks) and the service space supported by the plug-in uniCloud. The following is a detailed configuration description of uni_modules.config.json
{
"scripts": {
//Execute this script after updating the plug-in, and the currently updated plug-in ID can be acquired from process.env.UNI_MODULES_ID. If there are more than one ID, separate them by ","
"postupdate": "node scripts/upgrade.js",
// Execute this script before uploading the plug-in, and the currently updated plug-in ID can be acquired from process.env.UNI_MODULES_ID. If there are more than one ID, separate them by ","
"preupload": "node scripts/preupload.js",
//Execute this script after uploading the plug-in (no matter success or failed), and the currently updated plug-in ID can be acquired from process.env.UNI_MODULES_ID. If there are more than one ID, separate them by ","
"postupload": "node scripts/postupload.js"
},
"uni_modules": {
//Plug-in ID
"uni-id": {
//When both aliyun and tcb exist in the project, you can manually specify the service space to which the plugin belongs
"uniCloud": ["aliyun", "tcb"]
}
}
}
Tips
When uni_modules plug-in is released to plug-in market, it is usually necessary to ignore some directories or files, such as unpackage
, .hbuilderx
, node_modules
and so on, then the file can be ignored by npmignore file.
File name: .npmignore. Note that there is a dot at the beginning. Contents of a typical npmignore file are as follows:
.hbuilderx
unpackage
node_modules
package-lock.json
Notice
.npmignore
in the project root directory is effective for publishing projects and plug-in templates. uni_modules/Plug-in Id/.npmignore
Effective for published plug-insIn the root directory of the uni-app project, create the uni_modules directory, and you can click Create uni_modules directory
on the right-click menu of the project.
Tips:
src
, which is src/uni_modules
Create uni_modules plug-in
Plugin ID naming specification:
Tips
uni_modules
plug-in can be configured with three-party dependencies in the uni_modules->dependencies
node of package.json (the dependent plug-in must also be the uni_modules
plug-in). If it is an npm plug-in that relies on three parties, you can use the standard dependencies node configuration.When your plug-in is developed, you can publish it directly to the plug-in market (opens new window) for free or paid use by others. The plug-in market provides mechanisms such as realization and evaluation. Excellent plug-in authors can earn tens of thousands of dollars a month.
Release process:
Release to plug-in market
When your plug-in is released to the plug-in market, if you need to adjust some basic information in the plug-in market, such as Chinese name, description, keywords, and readme.md, you can right-click the Modify the plug-in basic information
directly in the plug-in directory.
Modify the plug-in basic information
When your plug-in has added new functions or fixed bugs, and a new version needs to be released, the operation is the same as that of the first release, and you can right-click the Release to plug-in market
directly in the plug-in directory.
Tips
Use HBuilderX to import the plug-ins
Tips
import {test} from '@/uni_modules/xx-yy/js_sdk/test.js'
{
"pages":[{
//Introduce the corresponding pages according to the directory where the plug-in is located
"path":"uni_modules/xx-yy/pages/demo/demo"
}]
}
Dependency of third-party plug-in installation
Update from the plug-in market
The uni_modules plug-in directory is standalone. If you no longer need the plug-in, you can delete it directly.
Tips
uni_modules
. For example, if your existing plug-in ID is xx-yy
, the directory structure is: uni_modules/xx-yy
{
"id": "Your plug-in ID"
}
Release to plug-in market
, select the classification, and fill in the plug-in information (consistent with the existing information in the plug-in market as much as possible)