A code fragment is a sharable mini project that can be used to share the development experience of Mini Programs and Mini Games, demonstrate the use of components and APIs, and reproduce development problems. Sharing the code fragment generates a link, with which anyone can import the fragment into the tool. If a clickable link in a webpage is a sharing link, clicking this link will automatically open the DevTools to the page for importing the code fragment. With the latest Weixin DevTools version, you can Use Chrome browser to click here to import code fragments.

Opening wechatide:// protocol link with browsers is not supported by Weixin DevTools versions prior to 1.02.1904280 starting 04/28/2019. Please install this version or later and use links starting with https://developers.weixin.qq.com/s/. The wechatide:// protocol link is still supported when importing code fragments into the tool.

# Creating Code Fragments

In the project selection interface of the DevTools, select the Code Fragment page on the right to view all the local code fragments and click on the bottom-right corner to create code fragments.

minicode

The code fragment name and local storage directory need to be provided when creating code fragments. AppID is only required when demonstrating operations that use an AppID. If the storage directory is empty, the quick-start templates below for Mini Programs and Mini Games can be selected.

minicode

Once the information is entered, click Create to complete the creation and open the code fragment.

# Main Code Fragment Interface

The main code fragment interface is different from that of other items in the following aspects:

  1. Functions like upload, Tencent Cloud, and test report application are not available;
  2. The last shared link is shown on the details page and can be copied with one click;
  3. The quick start template for the code fragment is smaller and has simpler features than normal projects.

minicode

# Sharing Code Fragments

Click the Share button on the toolbar to start sharing code fragments. To do this, the following information is required:

  • Project description: Describes the function and purpose of the code fragment
  • Whether an AppID is required: If so, we suggest that developers fill in the AppID when importing the code fragment to run it completely
  • Minimum library version: When developers open the imported code fragment, the base library version for debugging in the details page should not be lower than the specified version

A shared code fragment of a Mini Program is limited to 1MB in size, while that of a Mini Game is 1MB.

minicode

After sharing a code fragment, a sharing link will be displayed, which can be copied and shared to other developers. Then, these developers can import the code fragment by selecting it and pasting the link in the tool.

minicode

Apart from being pasted into the import page, the sharing link can also be set as a clickable link. If the href property of html <a> tag is set as a sharing link, for example, <a href="https://developers.weixin.qq.com/s/76b799966b6ead1837edac517cc02e02">code fragment example</a>, clicking this link will automatically open the DevTools to the page for importing the code fragment, and clicking Import will complete the import process. To provide a demo when posting in a developer community, please insert the code fragment sharing link as a hyperlink.

minicode

# Importing Code Fragments

The Import page can be opened by clicking Import on the bottom right of the page where the code fragment is selected, or clicking Import Code Fragment under the Project tab in the menu bar. During the import, the sharing link or code fragment ID is required, with the latter being the last part of the link. For example, the ID of https://developers.weixin.qq.com/s/76b799966b6ead1837edac517cc02e02 is 76b799966b6ead1837edac517cc02e02.

minicode

The storage directory and AppID can be selected, and the default storage directory is a temporary folder.

minicode