Configuration
The app.json
file in the Mini Program root directory is used to apply global configurations to Mini Programs. The file content is a JSON object with the following properties:
#
Configuration ItemsProperty | Type | Default Value | Required | Description |
---|---|---|---|---|
entryPagePath | string | - | ✓ | index page name |
pages | string[] | - | ✓ | Page Path List |
window | Object | - | - | Global default window behavior |
tabBar | Object | - | - | Behavior of the tab bar at the bottom of the page. |
subPackages | Object[] | - | - | subPackage structure configuration. |
#
windowProperty | Type | Default Value | Required | Description |
---|---|---|---|---|
navigationBarBackgroundColor | HexColor | #000000 | - | The navigation bar background color |
navigationBarButtonColor | HexColor | #707A8A | - | The button color in the navigation. |
navigationBarTitleText | string | - | ✓ | Title text of the navigation bar |
navigationBarTextStyle | string | white | - | The title color of the navigation bar, only supports black or white |
navigationStyle | string | default | - | The navigation bar style. Only the following values are supported. default : the default style. custom : custom navigation bar, only retains the Mini Program control button in the upper-right corner, click here for details. |
backgroundTextStyle | string | dark | - | The pull-down loading style, only dark and light are supported. |
backgroundColor | HexColor | #ffffff | - | The background color of the window. |
#
tabBarIf the Mini Program is a multi-tab app (which uses a tab bar at the bottom or top of the app window to switch between tabs), you can use the tabBar configuration item to specify the behavior of the tab bar and the pages displayed when the user switches between tabs.
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
color | HexColor | ✓ | The default color of the tab bar text, only supports hex color codes. | |
selectedColor | HexColor | ✓ | The color of the tab bar text when being selected, only supports hex color codes. | |
backgroundColor | HexColor | ✓ | The color of the tab bar background, only supports hex color codes. | |
borderStyle | string | black | The border color of the tab bar, only supports black and white . | |
list | array | ✓ | The tab list (see the list property description), supports 2 to 5 tabs. | |
position | string | bottom | The tabBar position, only supports bottom and top . | |
custom | boolean | false | A custom tabBar, click here for details. |
The list property accepts an array, which can only configure 2 to 5 tabs. The tabs are listed in the order of the array. Each item is an object with the following properties:
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
pagePath | string | ✓ | The page path, which must be defined first in pages. | |
text | string | ✓ | The text of tab buttons. | |
iconPath | string | The image path. The size of the icon is limited to 40 KB, suggested dimensions: 81px by 81px, online images are not supported. When position is set to top , the icon is not displayed. | ||
selectedIconPath | string | The image path for the selected icon. The size of the icon is limited to 40 KB, suggested dimensions: 81px by 81px, online images are not supported. When position is set to top , the icon is not displayed. |
#
subPackagesIn some cases, the developer needs to divide a Mini Program into different child packages, and package these child packages into different subpackages while building, so that users can load them as needed.
When building a subpackage project, one or more subpackages will be output. Each subpackaged Mini Program must contain a main package that includes the default startup/TabBar page and some common resources and JS scripts required by all subpackages. The sub-packages are divided according to the developer's configuration.
When the Mini Program starts, the main package is downloaded and the pages in the main package are started by default. When a user enters a page in a subpackage, the client downloads the corresponding subpackage and displays it after the download is completed.
Supported from SDK ^3.2.0, IDE ^2.9.0 and Native ^2.40.0
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
root | string | ✓ | root of subPackage | |
name | string | alias name | ||
pages | string[] | ✓ | page list related to root | |
independent | boolean | ✓ | If it is an independent subPackage |
#
useExtendedLibSpecifies the extension library to be referenced. The following projects are currently supported:
- react
When specified, is equivalent to introducing the latest version of the corresponding extension library npm Package, but also does not occupy the Mini Programs package volume. The rc tool version supports sub-packageing references. Usage is as follows:
use true
to use the latestVersion.
You can also specify the exact version you want to use.
#
prefetchRulesData prefetching can initiate a request in advance when the Mini Program is cold started, and cache the response of the request, and use the cached data in the actual request to reduce the time for network requests. The specific process is as follows:
#
Configure prefetch rulesData prefetching rules need to be configured in app.json, examples are as follows:
#
Configure variablesIn order to make configuration requests dynamic, we introduce configuration variables. Configuration variables have the format ${variable}. The process of assigning the variable is string replacement, replacing ${variable} in the prefetchRules configuration string with the variable's value.
#
Variable data sourceThere are three data sources for configuration variables, sorted by priority:
- The query parameter of the Mini Program page route
- Data stored in storage by developers
- The data returned by the getSystemInfo interface, such as language
The client starts to search for variables from the high-priority data source. If the corresponding variable is found, it does not continue to search, otherwise it continues to search for the next data source. If none of the data sources can find the corresponding variable, then no request will be made.
#
Request urlThe most basic thing that constitutes a request is the url. As long as there is a complete url, we can initiate a request. Currently we support variable in path and query of url, but host does not currently support.
When the prefetch configuration is as follows, assuming that the page route is pages/index/index?pageid=1000, and the developer’s storage stores the pageSize variable with a value of 10, then the final prefetch request will be https://developer.binance.com/1000?pagesize=10&pagenum=1
#
Request parametersThe value of the request address is the request parameter, which includes method, header, data and responseType, corresponding to the parameters of the bn.request API, and these parameters also support configuration variables. The specific rules for the default values of method, header, data and responseType are shown in the table below:
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
header | object | {'content-type': 'application/json'} | Request header | |
method | string | GET | Request method, support GET, POST | |
data | string or object | null | Request data, needs to be consistent to hit the cache | |
responseType | string | text | Response data type, optional value: text |
For example, suppose the request parameters are configured as follows:
If the page route is pages/index/index?pageid=1000, the developer’s storage stores the pageSize variable with a value of 10, and also stores the token variable with a value of test_token, then the parameters of the final prefetch request will be as follows show:
#
Use prefetch cachebn.request has added the usePrefetchCache parameter, and the return data has added isPrefetch to distinguish whether the data is prefetched or not. The example is as follows:
#
File PrefetchIn addition to prefetching network requests, we also support prefetching files. The file prefetch configuration is similar to the network request configuration, but the value of the request address is the local file path. The file path supports configuration variables.
For example, suppose the file prefetch rule are configured as follows:
If the page route is pages/index/index, and the client language is zh_CN, the variable language will be replaced with zh_CN (which is got from getSystemInfo API), then the final prefetch request will be file://nezha-i18n-data_zh_CN.json.
When the mini program launches, the client will start downloading file://nezha-i18n-data_zh_CN.json immediately with parallel download. If the value of mandatory
is true, the mini program will not start until the file is downloaded successfully, otherwise the mini program will start immediately (no blocking).
Developers can use the bn.getFileSystemManager API to read the file content. The example is as follows:
#
Page ConfigurationFor each Mini Program page, the .json file named after the Mini Program can also be used to configure the window behaviors of this page. The configuration items in the current page overwrite the corresponding window
configuration items in app.json. The file content is a JSON object, example:
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
initialRenderingCache | String | - | Add static value to enable static rendering cache. |
#
Build ConfigurationThe Build option can be configured in bmp.config/index.js. You can configure alias for build or global constants for the project. Example:
The detailed configurable properties are as follows.
#
aliasUsed to configure directory aliases, thus facilitating the writing of code reference paths.
For example, write a file reference using a relative path as follows.
To avoid writing multi-level relative paths, we can configure alias as follows:
With the above configuration, the src/components and src/utils directories can be configured as aliases, and the package.json and project.config.json files in the root directory can be configured as aliases, so that the references in the code are rewritten as follows:
In order for the editor (VS Code) to not report errors and continue to use the automatic path completion feature, we need to configure paths in jsconfig.json or tsconfig.json in the root of the project for the editor to recognize our aliases in the following form:
#
entryThis is used to specify the location of app.js.
For example, if the project's app.jsx is in src/app.jsx, then you can configure it like this:
and app.config.js must be in the same directory as the specified app.js
#
webpackChainCustomize the Webpack configuration.
This function receives two arguments. The first argument is the webpackChain object, which can be modified by referring to the webpack-chain API, and the second argument is the webpack instance.
Exmaple:
#
defineConstantsThis is used to configure some global variables for use in the code.
The configuration can be found in Webpack DefinePlugin Example: