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:
|entryPagePath||-||✓||index page name|
|pages||-||✓||Page Path List|
|window||-||-||Global default window behavior|
|tabBar||-||-||Behavior of the |
|subPackages||-||-||subPackage structure configuration.|
|navigationBarBackgroundColor||#000000||-||The navigation bar background color|
|navigationBarButtonColor||#707A8A||-||The button color in the navigation.|
|navigationBarTitleText||-||✓||Title text of the navigation bar|
|navigationBarTextStyle||white||-||The title color of the navigation bar, only supports black or white|
|navigationStyle||default||-||The navigation bar style. Only the following values are supported. |
|backgroundTextStyle||dark||-||The pull-down loading style, only dark and light are supported.|
|backgroundColor||#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.
|color||✓||The default color of the tab bar text, only supports hex color codes.|
|selectedColor||✓||The color of the tab bar text when being selected, only supports hex color codes.|
|backgroundColor||✓||The color of the tab bar background, only supports hex color codes.|
|borderStyle||black||The border color of the tab bar, only supports |
|list||✓||The tab list (see the |
|position||bottom||The tabBar position, only supports |
|custom||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:
|pagePath||✓||The page path, which must be defined first in pages.|
|text||✓||The text of tab buttons.|
|iconPath||The image path. The size of the icon is limited to 40 KB, suggested dimensions: 81px by 81px, online images are not supported. When |
|selectedIconPath||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 |
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
|root||✓||root of subPackage|
|pages||✓||page list related to root|
|independent||✓||If it is an independent subPackage|
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:
The 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.
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.
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:
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:
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.
This is used to configure some global variables for use in the code.
The configuration can be found in Webpack DefinePlugin Example: