Requirements: The independent subpackage is entered by scanning the code and needs to use the vant component library. However, since the independent subpackage cannot use the resources of the main package, it is necessary to import the vant component in the independent subpackage
The first step is to initialize through the cmd window in the corresponding independent subpackage
npm init -y
The second step, install vant/weapp through npm
npm i @vant/weapp -S --production
The third step is to build the npm package
Specifically, use the vant component through npm:
The rendering after construction
Note: When the build is complete, there are no additional
miniprogram_npm
files
so add a new file under the independent subpackageproject.config.json
The fourth step, use components
Introduce components under the json of the independent subpackage page
{
"usingComponents": {
"van-button": "@vant/weapp/button/index"
}
}
Use components on the page
<van-button type="default">默认按钮</van-button>
<van-button type="primary">主要按钮</van-button>
<van-button type="info">信息按钮</van-button>
<van-button type="warning">警告按钮</van-button>
<van-button type="danger">危险按钮</van-button>
Effect
Finally, on the issue of error reporting
The following error occurs
- Just delete the components that are not used by the current independent subpackage, because the components that are not used will be automatically ignored.
不影响使用
- But it is recommended to keep it, anyway, when the code is uploaded, it will be filtered out
无依赖代码文件