Code snippet is a type of shareable mini project that can be used to share development experience, show component and API usage, reproduce development issues, etc. of Mini Programs and Mini Games. By sharing a code snippet, an URL will be created. Anyone who has access to this URL is allowed to import this code snippet in the tools. If the tappable URL on the website points to the shared link, then tapping the URL will also automatically open the tools and enter the code snippet import page. With the latest version of the development tools, you can tap here to try code snippet import.
Create a code snippet
In the project selection interface of the tools, you can select the code snippet page on the right to view all local code snippets, while you can tap to create a code snippet in the bottom right corner.
To create a code snippet, it is required to enter the name of the code snippet and the local storage directory. AppID is not required, unless you need to demonstrate an operation that relies on AppID. If the storage directory is empty, you can select a quick start template for Mini Programs, Mini Games, etc. at below.
After the information is entered correctly, you can click Create to finish and open the code snippet.
Code Snippets Main Interface
There are a few major differences between the code snippets main interface and normal projects:
- No uploading, Tencent Cloud, test report application and other features.
- Previous shared URLs will be displayed on the Details page, and can be copied with one tap.
- The quick start template of code snippets is different from that of normal projects, with a smaller volume and more streamlined functions.
Share a code snippet
Click the Share button on the toolbar to open the process of sharing code snippets. You need to enter the following in the sharing information:
- Project description: Briefly introduce the function and purpose of this code snippet
- Is AppID needed?: If so, developers will be advised to enter the AppID when they import the code snippet in order to run the code snippet completely.
- Minimum library version: When developers open the imported code snippet, the debugging basic library of the Details page will not be lower than the specified version.
The maximum size of a shared Mini Program code snippet is 100KB, while that of a Mini Game code snippet is 200KB.
The shared URL - which will be displayed upon successful sharing - can be copied and shared to other developers, who can import the code snippet simply by choosing Import Code Snippets in the tools and pasting the URL.
In addition to being able to be pasted into the Import page, the shared URL can also be set as a tappable URL. If the
href property is set as shared URL, e.g.
<a href="wechatide://minicode/76b799966b6ead1837edac517cc02e02">Code fragment sample</a>, users will automatically open the tools and enter the code snippet import page upon tapping the URL, and then tap Import to complete. If you want to provide a demo when posting to the developers community, you can insert a hyperlink with the shared URL of the code snippet.
Import a code snippet
On the bottom right corner of the page that selects code snippets, you can go to the import page by tapping Import, or by tapping Import Code Snippet under the Projects tab on the menu bar. A shared URL or code snippet ID is required for import. The last part of the URL is the ID of the code snippet, for example, the ID of
You can choose the storage directory and AppID when importing. The storage directory is by default in the Temp folder.