Skip to main content


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 Items#

PropertyTypeDefault ValueRequiredDescription
entryPagePathstring-index page name
pagesstring[]-Page Path List
windowObject--Global default window behavior
tabBarObject--Behavior of the tab bar at the bottom of the page.
subPackagesObject[]--subPackage structure configuration.


PropertyTypeDefault ValueRequiredDescription
navigationBarBackgroundColorHexColor#000000-The navigation bar background color
navigationBarButtonColorHexColor#707A8A-The button color in the navigation.
navigationBarTitleTextstring-Title text of the navigation bar
navigationBarTextStylestringwhite-The title color of the navigation bar, only supports black or white
navigationStylestringdefault-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.
backgroundTextStylestringdark-The pull-down loading style, only dark and light are supported.
backgroundColorHexColor#ffffff-The background color of the window.


If 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.

PropertyTypeDefault ValueRequiredDescription
colorHexColorThe default color of the tab bar text, only supports hex color codes.
selectedColorHexColorThe color of the tab bar text when being selected, only supports hex color codes.
backgroundColorHexColorThe color of the tab bar background, only supports hex color codes.
borderStylestringblackThe border color of the tab bar, only supports black and white.
listarrayThe tab list (see the list property description), supports 2 to 5 tabs.
positionstringbottomThe tabBar position, only supports bottom and top.
custombooleanfalseA 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:

PropertyTypeDefault ValueRequiredDescription
pagePathstringThe page path, which must be defined first in pages.
textstringThe text of tab buttons.
iconPathstringThe 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.
selectedIconPathstringThe 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.


In 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

PropertyTypeDefault ValueRequiredDescription
rootstringroot of subPackage
namestringalias name
pagesstring[]page list related to root
independentbooleanIf it is an independent subPackage


Specifies 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.

{  "useExtendedLib": {    "react": true  }}

You can also specify the exact version you want to use.

{  "useExtendedLib": {    "react": "17.0.2"  }}


Data 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 rules#

Data prefetching rules need to be configured in app.json, examples are as follows:

{  "prefetchRules": {    // launch path that need to be configured with prefetch requests    "pages/index/index": {      // request url      "${pageid}": {        // request method        "method": "POST",        // request header        "header": {          "token": "${token}"        },        // request body        "data": {          "pageSize": "${pageSize}",          "pageNum": 1        },        // request response type        "responseType": "text"      }    },    // match all launch paths    "*": {      // local file path, language is the variable      "file://nezha-i18n-data_${language}.json": {        // whether to wait for the file download to complete when starting the mini program        "mandatory": true      }    }  }}

Configure variables#

In 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 source#

There are three data sources for configuration variables, sorted by priority:

  1. The query parameter of the Mini Program page route
  2. Data stored in storage by developers
  3. 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 url#

The 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

{  "prefetchRules": {    "pages/index/index": {      "${pageid}?pagesize=${pageSize}&pagenum=1": {}    }  }}

Request parameters#

The 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:

PropertyTypeDefault ValueRequiredDescription
headerobject{'content-type': 'application/json'}Request header
methodstringGETRequest method, support GET, POST
datastring or objectnullRequest data, needs to be consistent to hit the cache
responseTypestringtextResponse data type, optional value: text

For example, suppose the request parameters are configured as follows:

{  "${pageid}": {    "method": "POST",    "header": {      "token": "${token}"    },    "data": {      "pageSize": "${pageSize}",      "pageNum": 1    }  }}

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:

{  "": {    "method": "POST",    "header": {      "token": "test_token"    },    "data": {      "pageSize": "10",      "pageNum": 1    }  }}

Use prefetch cache#

bn.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:

{  "prefetchRules": {    "pages/index/index": {      "${sid}?testid=${testid}&testdata=${sData}": {        "method": "POST",        "header": {          "testCookie": "${sCookie}",          "token": "xxxs1823730"        },        "data": {          "mData": "${mData}"        },        "responseType": ""      }    }  }}
//storageconst testCookie = bn.getStorageSync('sData')const sCookie = bn.getStorageSync('sCookie')const mData = bn.getStorageSync('mData')
//requestconst token = 'xxxs1823730'const { sid, testid } = option.queryconst url = `${sid}?testid=${testid}&testdata=${sData}`const header = { testCookie, token }const data = { mData }
bn.request({  url,  header,  data,  method: 'POST',  dataType: 'json',  responseType: 'text',  usePrefetchCache: true,  success: res => {    console.log('Whether the returned data is from prefetching:', res.isPrefetch)    console.log('Response data:',  },})

File Prefetch#

In 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:

{  "prefetchRules": {    "pages/index/index": {      "file://nezha-i18n-data_${language}.json": {        "mandatory": true      }    }  }}

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:

const fs = bn.getFileSystemManager()const filePath = 'file://nezha-i18n-data_zh_CN.json'const res = fs.readFileSync(filePath, 'utf8')console.log('File content:', res)

Page Configuration#

For 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:

{  "navigationBarBackgroundColor": "#ffffff",  "navigationBarTextStyle": "black",  "navigationBarTitleText": "Weixin API feature demo",  "backgroundColor": "#eeeeee",  "backgroundTextStyle": "light",  "initialRenderingCache": "static"}
PropertyTypeDefault ValueRequiredDescription
initialRenderingCacheString-Add static value to enable static rendering cache.

Build Configuration#

The Build option can be configured in bmp.config/index.js. You can configure alias for build or global constants for the project. Example:

const path = require('path')module.exports = {  // settings for alias  alias: {    '@': path.resolve('./src'),  },  // entry of the mini program  entry: {    app: ['src/app'],  },  // global constants  defineConstants: {},  // custom webpack-chain settings  webpackChain: {},}

The detailed configurable properties are as follows.


Used to configure directory aliases, thus facilitating the writing of code reference paths.

For example, write a file reference using a relative path as follows.

import A from '../../componnets/A'

To avoid writing multi-level relative paths, we can configure alias as follows:

module.exports = {  // ...  alias: {    '@/components': path.resolve(__dirname, '..', 'src/components'),  },}

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:

import A from '@/components/A'

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:

{  "compilerOptions": {    "baseUrl": ".",    "paths": {      "@/components/*": ["./src/components/*"],    }  }}


This 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:

module.exports = {  // ...  entry: {    app: ['src/app'],  },}

and app.config.js must be in the same directory as the specified app.js


Customize 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.


// example of using raw-loader,which can load md file into codesmodule.exports = {  // ...  webpackChain(chain, webpack) {    chain.merge({      module: {        rule: {          myloader: {            test: /\.md$/,            use: [              {                loader: 'raw-loader',                options: {},              },            ],          },        },      },    })  },}


This is used to configure some global variables for use in the code.

The configuration can be found in Webpack DefinePlugin Example:

module.exports = {  // ...  defineConstants: {    A: '"a"', // JSON.stringify('a')  },}