title: Global Configuration

The app.config.js file in the root directory is used for global configuration of the mini-program. The configuration items follow the WeChat mini-program specification and are unified for all platforms.

Attention.

  1. The js file referenced by require or import in app.config.js currently does not go through the Babel compilation syntax.
  2. Differentiation logic can be implemented using the process.env.TARO_ENV variable as a conditional judgment.
  3. app.config.js does not support multi-terminated files like app.weapp.js, which does not work.

Common Configuration

Configurations supported in H5, React Native, and all Mini-program.

Propery Type Required Description
pages String Array yes List of page paths
window Object no Global default window
tabBar Object no Bottom tab bar
subPackages Object Array no Subcontract configuration

pages

Used to specify which pages the mini program consists of, each corresponding to a page path + file name information. The file name does not need to write the file suffix, the framework will automatically go to find the corresponding location of the file for processing.

The first item of the array represents the initial page of the mini-program (home page). If you add/drop pages in the mini-program, you need to modify the pages array.

Development Directory:

  1. ├── app.js
  2. ├── app.json
  3. ├── app.wxss
  4. ├── pages
  5. │── index
  6. ├── index.wxml
  7. ├── index.js
  8. ├── index.json
  9. └── index.wxss
  10. └── logs
  11. ├── logs.wxml
  12. └── logs.js
  13. └── utils

you need to write in the entry file configuration

```jsx title=”app.config.js” export default { pages: [ ‘pages/index/index’, ‘pages/logs/logs’ ] }

  1. ### window
  2. Set the status bar, navigation bar, title, and window background color of the mini-program with the following configuration items:
  3. | Proerty | Type | Defalut | Description |
  4. | - | - | - | - |
  5. | navigationBarBackgroundColor | HexColor | #000000 | Navigation bar background color,eg: #000000 |
  6. | navigationBarTextStyle | String | white | Navigation bar header color, supported only black / white |
  7. | navigationBarTitleText | String | | Navigation bar title text |
  8. | navigationStyle | String | default | Navigation bar style, only the following values are supported: default: defalut style, custom: Customize the navigation bar, keeping only the top-right corner button |
  9. | backgroundColor | String | | Background color of the window |
  10. | backgroundTextStyle | String | dark | The drop-down loading style, only supported dark / light |
  11. | backgroundColorTop | String | #ffffff | Background color for top window, supported on iOS only |
  12. | backgroundColorBottom | String | #ffffff | Background color for the bottom window, supported on iOS only |
  13. | enablePullDownRefresh | boolean | false | Whether to enable drop-down refresh of the current page |
  14. | onReachBottomDistance | Number | 50 | The distance from the bottom of the page when the page pull-up bottom event is triggered, the unit is px |
  15. |pageOrientation | String | portrait | Screen rotation settings, support auto / portrait / landscape |
  16. #### Support as follows
  17. | Property | WeChat Mini-Program | Baidu Smart-Program | ByteDance Mini-Program | Alipay Mini-Program | H5 | React Native |
  18. | - | - | - | - | - | - | - |
  19. | navigationBarBackgroundColor | ✔️ | ✔️|✔️|✔️|✔️|✔️|
  20. | navigationBarTextStyle | ✔️ | ✔️|✔️| |✔️|✔️|
  21. | navigationBarTitleText | ✔️ | ✔️|✔️| ✔️ |✔️|✔️|
  22. | navigationStyle | ✔️ (WeChat App 6.6.0) | ✔️(Baidu App 11.1.0)|✔️| | ✘| ✘|
  23. | backgroundColor | ✔️ | ✔️|✔️| |✘|✘|
  24. | backgroundTextStyle | ✔️ | ✔️|✔️| |✘|✘|
  25. | backgroundColorTop |✔️ (WeChat App 6.5.16 | ✘|✔️| |✘|✘|
  26. | backgroundColorBottom |✔️ (WeChat App 6.5.16 | ✘|✔️| |✘|✘|
  27. | enablePullDownRefresh | ✔️ | ✔️|✔️| ✔️ |✘|✘|
  28. | onReachBottomDistance | ✔️ | ✔️|✔️| |✘|✘|
  29. |pageOrientation | ✔️ 2.4.0 (auto) / 2.5.0 (landscape) | ✘|✘| |✘|✘|
  30. #### Code example
  31. ```jsx title="app.config.js"
  32. export default {
  33. pages: [
  34. 'pages/index/index',
  35. 'pages/logs/logs'
  36. ],
  37. window: {
  38. navigationBarBackgroundColor: '#ffffff',
  39. navigationBarTextStyle: 'black',
  40. navigationBarTitleText: 'WeChat interface function demo',
  41. backgroundColor: '#eeeeee',
  42. backgroundTextStyle: 'light'
  43. }
  44. }

tabBar

If the mini-program is a multi-tab application, The tabBar configuration item allows you to specify how the tab bar should behave and the corresponding page to be displayed when the tab is switched.

The configuration items are as follows:

Property Type Required Default Description
color HexColor(Hexadecimal color values) Yes Default color for text on tab, only support Hexadecimal color value
selectedColor HexColor Yes Text selection color on tab, only support Hexadecimal color value
backgroundColor HexColor Yes tab backgroundColor , only support Hexadecimal color value
borderStyle String Yes black tabbar border color, only support black / white
list Array Yes tab list of at least 2 and at most 5 tabs
position String No bottom tabBar position, only support bottom / top
custom Boolean No false custom tabBar

where list accepts an array of at least 2 and at most 5 tabs. The tabs are sorted in the order of the array and each item is an object with the following Property values.

Property Type Required Description
pagePath String Yes The page path, must be defined first in the pages
text String Yes Button text on tab
iconPath String No Image path, icon size limit is 40kb, recommended size is 81px * 81px, web images are not supported.
When position is top, the icon is not displayed.
selectedIconPath String No Image path when selected, icon size limit is 40kb, recommended size is 81px * 81px, web images are not supported.
When position is top, the icon is not displayed.

Support as follows

Property WeChat Mini-Program Baidu Smart-Program ByteDance Mini-Program Alipay Mini-Program H5 RN
color ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
selectedColor ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
backgroundColor ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
borderStyle ✔️ ✔️ ✔️ ✔️ ✔️
list ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
position ✔️ ✔️
custom ✔ (Base library 2.5.0 or higher)

subPackages

H5 and RN can merge subPackages into pages

When enable Subpackage Loading, declare the project subcontract structure

Mini-program specific property

Property is only supported in Mini-program, H5 and RN are not supported.

Property Type Description
networkTimeout Object Network timeout time
debug Boolean Whether to enable debug mode, default off
permission Object Mini-program interface permission-related settings
requiredBackgroundModes String Array Capabilities that need to be used in the background, such as “Music Play”
preloadRule Object Subpackage pre-download rules
entryPagePath String Default Launch Home
workers String Worker code directory
navigateToMiniProgramAppIdList String Array For a list of jumping mini-program, see wx.navigateToMiniProgram

networkTimeout

Global Configuration - 图1 Global Configuration - 图2 Global Configuration - 图3 Global Configuration - 图4

Timeout time for each type of network request, All units are in milliseconds.

Property Type Required Default Description
request Number No 60000 Timeout for Taro.request , unit: milliseconds
connectSocket Number No 60000 Timeout for Taro.connectSocket , unit: milliseconds
uploadFile Number No 60000 Timeout for Taro.uploadFile , unit: milliseconds
downloadFile Number No 60000 Timeout for Taro.downloadFile , unit: milliseconds

debug

Support situation: Global Configuration - 图5 Global Configuration - 图6 Global Configuration - 图7

You can enable debug mode in developer tools. In the console panel of developer tools, debug information is given in the form of info, which includes Page registration, page routing, data update, event triggering, etc. It can help developers to quickly locate some common problems.

permission

Support situation: Global Configuration - 图8 Global Configuration - 图9 Global Configuration - 图10 Global Configuration - 图11

Mini-programInterface Permissionsrelated settings. The field type is Object and the structure as follow:

Property Type Required Defalut Description
scope.userLocation PermissionObject No Location-related permission statement

PermissionObject structure:

Property Type Required Defalut Description
desc string Yes Description of the interface usage displayed when obtaining permissions. Maximum 30 characters

Code Examples

```js title=”app.config.js” export default { pages: [ ‘pages/index/index’, ‘pages/logs/logs’ ], permission: { ‘scope.userLocation’: { desc: ‘Your location information will be used to show the effect of the mini-program location interface’ } } }

  1. ![image](https://img10.360buyimg.com/ling/jfs/t1/132830/23/12399/20429/5f893793Ebafa6939/b5f6a390ac9bfd79.jpg)
  2. ### requiredBackgroundModes
  3. Support situation: <img src="https://storage.jd.com/cjj-pub-images/icon_%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F.png" width="25px" style={{verticalAlign: 'middle' }} /> <img src="https://storage.jd.com/cjj-pub-images/icon_%E7%99%BE%E5%BA%A6%E8%BD%BB%E5%BA%94%E7%94%A8.png" width="25px" style={{verticalAlign: 'middle' }} /> <img src="https://storage.jd.com/cjj-pub-images/icon_QQ%E5%B0%8F%E7%A8%8B%E5%BA%8F.png" width="25px" style={{verticalAlign: 'middle' }} />
  4. Declare the ability to require background operation, of type array. The following projects are currently supported.
  5. - `audio`: Background music playback
  6. - `location`: Background Location
  7. #### Code Example
  8. ```js title="app.config.js"
  9. export default {
  10. "pages": ["pages/index/index"],
  11. "requiredBackgroundModes": ["audio", "location"]
  12. }

Note: The interface running in the background is affirmed here, and it can take effect directly on the development version and experience version, while the official version still needs to pass the audit.

preloadRule

Support situation: Global Configuration - 图12 Global Configuration - 图13 Global Configuration - 图14

Declare the rules for subcontracting pre-downloads.

entryPagePath

Support situation: Global Configuration - 图15 Global Configuration - 图16

Set the default launch path (home page) of the mini-program, common scenario is to launch from WeChat list page dropdown, mini-program list launch, etc. If not filled, it will default to the first item in the pages list. The parameter with page path is not supported.

Code Examples

```js title=”app.config.js” export default { “entryPagePath”: “pages/index/index” }

  1. ### workers
  2. Support situation: <img src="https://storage.jd.com/cjj-pub-images/icon_%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F.png" width="25px" style={{verticalAlign: 'middle' }} /> <img src="https://storage.jd.com/cjj-pub-images/icon_QQ%E5%B0%8F%E7%A8%8B%E5%BA%8F.png" width="25px" style={{verticalAlign: 'middle' }} />
  3. Set the directory where Worker code is placed when using Worker to handle multi-threaded tasks.
  4. - [Wechat Mini-program Documents - Worker](https://developers.weixin.qq.com/miniprogram/dev/framework/workers.html)
  5. - [QQ Mini-program Documents - Worker](https://q.qq.com/wiki/develop/miniprogram/frame/basic_ability/basic_multiworker.html)
  6. ### navigateToMiniProgramAppIdList
  7. Support situation: <img src="https://storage.jd.com/cjj-pub-images/icon_%E5%AD%97%E8%8A%82.png" width="25px" style={{verticalAlign: 'middle' }} /> <img src="https://storage.jd.com/cjj-pub-images/icon_QQ%E5%B0%8F%E7%A8%8B%E5%BA%8F.png" width="25px" style={{verticalAlign: 'middle' }} />
  8. When the mini-program needs to jump to other mini-program using the [Taro.navigateToMiniProgram](https://developers.weixin.qq.com/miniprogram/dev/api/wx.navigateToMiniProgram.html) interface,
  9. you need to declare the list of appId of the mini-program you want to jump to in the configuration file, you can fill in up to 10
  10. ## WeChat Mini-program specific Property
  11. Property that is only supported in WeChat mini-program. <img src="https://storage.jd.com/cjj-pub-images/icon_%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F.png" width="25px" style={{verticalAlign: 'middle' }} />
  12. | Property | Type | Description |
  13. | :--- | :--- | :--- |
  14. | [functionalPages](#functionalpages) | Boolean | Whether to enable the plugin function page, default off |
  15. | [plugins](#plugins) | Object | Plugins used |
  16. | [resizable](#resizable) | Boolean | Whether the iPad mini-program supports screen rotation, the default is off |
  17. | [usingComponents](#usingcomponents) | Object | Global custom component configuration |
  18. | [sitemapLocation](#sitemaplocation) | String | Specify the location of sitemap.json |
  19. | [style](#style) | String | Specify the use of the upgraded weui style |
  20. | [useExtendedLib](#useextendedlib) | Object | Specify the extension library to be referenced |
  21. | [entranceDeclare](#entrancedeclare) | Object | WeChat messages open with mini-program |
  22. | [darkmode](#darkmode) | boolean | Mini-program support DarkMode |
  23. | [themeLocation](#themelocation) | String | Specify the location of theme.json |
  24. | [lazyCodeLoading](#lazycodeloading) | String | Configure custom component code for on-demand injection |
  25. | [singlePage](#singlepage) | Object | Single page mode related configuration |
  26. ### functionalPages
  27. > Base library 2.1.0 and above support
  28. Plugin owner mini-program needs to set this item to enable [Plugin Features Page](https://developers.weixin.qq.com/miniprogram/dev/framework/plugin/functional-pages.html)。
  29. ### plugins
  30. > Base library 1.9.6 and above support
  31. Declare the [plugin](https://developers.weixin.qq.com/miniprogram/dev/framework/plugin/using.html) use by the mini-program。
  32. ### resizable
  33. > Base library 2.3.0 and above support
  34. Mini-program running on iPad can be set to support[Screen Rotation](https://developers.weixin.qq.com/miniprogram/dev/framework/view/resizable.html)。
  35. For mini-program running on PC, users can drag the window size in any proportion, and can also maximize the window in the mini program menu.
  36. ### usingComponents
  37. > WeChat Developer Tools version 1.02.1810190 and above support
  38. The custom components declared here are considered global custom components and can be used directly in pages or custom components within the mini program without further declaration.
  39. ### sitemapLocation
  40. Specify the location of the [sitemap.json](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/sitemap.html) , The default is `sitemap.json`, which is the `sitemap.json` file named in the root directory.
  41. ### style
  42. > Base library 2.8.0 and above support
  43. WeChat App client 7.0 started with a major UI revamp. The mini-program has also undergone a style upgrade of the basic components. Configuring `"style": "v2"` in `app.json` indicates that the new version of the component style is enabled.
  44. The components involved in this change are `button` `icon` `radio` `checkbox` `switch` `slider`. You can go to the sample mini program to experience it.
  45. ### useExtendedLib
  46. > Base library 2.2.1 and above support
  47. Specify the extension library to be referenced. The following projects are currently supported.
  48. - weui: WeUI Component Library
  49. It is equivalent to introducing the latest version of the npm package associated with the corresponding extension library, without taking up the package size of the mini-program.
  50. The rc tools version supports subpackage references. The usage is as follows.
  51. #### Code example
  52. ```js title="app.config.js"
  53. export default {
  54. "useExtendedLib": {
  55. "weui": true
  56. }
  57. }

entranceDeclare

Supported by WeChat App version 7.0.9 and above, iOS is not supported yet

Chat location messages are opened with taxi-like mini-program,refer to details

Code example

```js title=”app.config.js” export default { “entranceDeclare”: { “locationMessage”: { “path”: “pages/index/index”, “query”: “foo=bar” } } }

  1. ### darkmode
  2. > Developer Tools 1.03.2004271 and above supported, Base Library 2.11.0 and above supported
  3. WeChat iOS App `7.0.12` version and Android App `7.0.13` version officially support `DarkMode`.You can configure `"darkmode": true` to indicate the current mini-program can be adapted to `DarkMode`, all basic components will display different default styles according to the system theme, `navigation bar` and `tab bar` will also be automatically switched according to the developer's configuration.
  4. After the configuration, please follow the [DarkMode Adaptation Guide](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/darkmode.html) to do the adaptation work other than the basic style by yourself.
  5. #### Code Example
  6. ```js title="app.config.js"
  7. export default {
  8. "darkmode": true
  9. }

themeLocation

Customize the path to theme.json, When "darkmode":true is configured, the current profile is a Required item.

Code Example

```js title=”app.config.js” export default { “themeLocation”: “/path/to/theme.json” }

  1. ### lazyCodeLoading
  2. > Base library 2.11.1 and above support, below 2.11.1 compatible but no optimization effect
  3. Normally, during the launch of the mini-program, the code of all pages and custom components are injected, and custom components and pages that are not used in the current page are not actually used after the injection.
  4. Since the base library version `2.11.1`, mini-program support selective injection of code necessary to reduce the mini-program startup time and runtime memory.
  5. #### Code Example
  6. ```js title="app.config.js"
  7. export default {
  8. "lazyCodeLoading": "requiredComponents"
  9. }

singlePage

Supported by Base Library 2.11.3 and above, currently opens in single page mode after sharing to friends (Beta)

Single page mode related configuration:

Property Type Required Defalult Description
navigationBarFit String No Automatic adjustment by default, float if the original page is a custom navigation bar, squeezed for No The intersection status of the navigation bar with the page. A value of float means that the navigation bar floats on the page and intersects with the page; a value of squeezed means that the page is squeezed by the navigation bar and does not intersect with the page.

Baidu Smart-program specific Property

Properties that are only supported in Baidu smart-program. Global Configuration - 图17

Property Type Description
routes Array Object Custom routing-related settings
dynamicLib Object Introducing dynamic libraries

routes

Base Library 3.160.3 and above support

For more details, see Custom Routes

routes is an array, each item in the array represents a set of routing rules, specifically containing the following fields.

Property Type Required Description Example
path String Yes Access Path “home”
page String Yes Page source code file paths, starting from the root of the mini-program package “pages/home/index”

Code Example

```js title=”app.config.js” export default { “pages”: [ “pages/home/home”, “pages/list/list”, “pages/detail/detail” ], “subPackage”: [ { “root”: “packageA”, “pages”: [ “pages/home/home”, “pages/list/list”, “pages/detail/detail” ] } ], “routes”: [ {

  1. "path": "home",
  2. "page": "pages/home/home"
  3. },
  4. {
  5. "path": "list",
  6. "page": "pages/list/list"
  7. },
  8. {
  9. "path": "foo/bar",
  10. "page": "pages/list/list"
  11. }

] }

  1. ### dynamicLib
  2. For more information, please refer to [Using dynamic libraries](https://smartprogram.baidu.com/docs/develop/framework/dynamiclib_use/)
  3. ## QQ mini-program specific Property
  4. Properties that are only supported in QQ mini-program. <img src="https://storage.jd.com/cjj-pub-images/icon_QQ%E5%B0%8F%E7%A8%8B%E5%BA%8F.png" width="25px" style={{verticalAlign: 'middle' }} />
  5. | Property | Type | Description |
  6. | :--- | :--- | :--- |
  7. | [groupIdList](#groupidlist) | String Object | You need to open the list of group numbers for the group profile card |
  8. ### groupIdList
  9. For more information, please refer to [Button](https://q.qq.com/wiki/develop/miniprogram/component/form/button.html)
  10. ## Jingdong mini-program specific Property
  11. Properties that are only supported in Jingdong mini-program.<img src="https://storage.jd.com/cjj-pub-images/icon_%E4%BA%AC%E4%B8%9C%E5%B0%8F%E7%A8%8B%E5%BA%8F.png" width="25px" style={{verticalAlign: 'middle' }} />
  12. | Property | Type | Description |
  13. | :--- | :--- | :--- |
  14. | [pageAlias](#pagealias) | Object | Page alias |
  15. | [quickMenu](#quickmenu) | Object | In-button menu configuration |
  16. ### pageAlias
  17. Page alias, you can configure an alias for pages inside `pages`, which can be used when opening mini-programs, if the `path` path is unknown or the `path` path is too long, you need to use it with the mini-program calling protocol `openapp` protocol.
  18. #### Code Example
  19. ```js title="app.config.js"
  20. export default {
  21. "pages": [
  22. "pages/index/index",
  23. "pages/my/my"
  24. ],
  25. "window": {
  26. "navigationBarTitleText": "京东小程序 Demo"
  27. },
  28. "tabBar": {
  29. "list": [{
  30. "pagePath": "pages/index/index",
  31. "text": "首页"
  32. }, {
  33. "pagePath": "pages/my/my",
  34. "text": "个人中心"
  35. }]
  36. },
  37. "debug": true,
  38. "pageAlias":{
  39. "index":"pages/index/index",
  40. "my":"pages/my/my"
  41. }
  42. }

openapp expample as follow:

  1. openapp.jdmobile://virtual?params={"category":"jump","des":"jdmp","appId":"ao123","vapptype":"1","path":"","pageAlias":"my","param":{}}

The above example will open the pages/my/my page with appId of ao123.

Note: The page path in pageAlias must exist in pages; multiple aliases can correspond to the same page address, and aliases cannot be repeated. For more details of openapp protocol, please refer to Open Mini-program This feature requires Jingdong app version 9.3.4 and mini-program engine 1.10.13 and above.

quickMenu

Some of the menus inside the buttons can be shown and hidden by configuring switches, the default is true display state. The configurable menus as follow:

Property Type Required Defalut Description
share Boolean No true Whether to show the push to friends (share) menu
favorite Boolean No true Whether to show the focus menu
sendToDesktop Boolean No true Whether to show send to desktop menu, only available for Android

In the following example, the Send to Friends, Follow and Send to Desktop menus will all be hidden and will not be displayed, as follows.

Code Example

js title="app.config.js" export default { "pages": [ "pages/index/index", "pages/my/my" ], "window": { "navigationBarTitleText": "京东小程序 Demo" }, "quickMenu":{ "share":false, "favorite":false, "sendToDesktop":false } }

The menu inside quickMenu can only be hidden if the boolean false is configured, and if there is an API that can control the hiding of certain menus, the priority of the API is greater than the configuration here, which is a global configuration and is only supported in app.json.