Small program - independent subcontracting using npm third-party (vant) component library

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

insert image description here
Specifically, use the vant component through npm:

The rendering after construction

insert image description here

Note: When the build is complete, there are no additional miniprogram_npmfiles
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
insert image description here

Finally, on the issue of error reporting

The following error occurs
insert image description here

  • 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无依赖代码文件

Guess you like

Origin blog.csdn.net/weixin_47124112/article/details/128532945