Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

关于按需引用组件的说明 #66

Open
b2nil opened this issue Dec 4, 2020 · 3 comments
Open

关于按需引用组件的说明 #66

b2nil opened this issue Dec 4, 2020 · 3 comments

Comments

@b2nil
Copy link
Owner

b2nil commented Dec 4, 2020

如需按需引用组件,请从 taro-ui-vue3/lib 目录中引用。
样式按需引用,仍需从 taro-ui-vue3/dist/style 目录中引用。

方式一

import { AtButton } from 'taro-ui-vue3/lib'
import "taro-ui-vue3/dist/style/components/button.scss"

方式二

  • 在 webpack 配置中,将 taro-ui-vue3 的 alias 指向 taro-ui-vue3/lib
// config/index.js
alias: {
  'taro-ui-vue3$': 'taro-ui-vue3/lib'
}
  • 然后从 taro-ui-vue3 中引用组件
 import { AtButton } from 'taro-ui-vue3'
 import "taro-ui-vue3/dist/style/components/button.scss"
@b2nil b2nil added the enhancement New feature or request label Dec 4, 2020
@b2nil b2nil pinned this issue Dec 4, 2020
@b2nil
Copy link
Owner Author

b2nil commented Dec 4, 2020

相关 issues:#57#64

@b2nil
Copy link
Owner Author

b2nil commented Dec 5, 2020

一些编译后的本地代码大小数据比较:

  • taro-ui-vue3-demo 为例(引用了 taro-ui-vue3 的全部组件)

    编译命令 taro-ui-vue3/lib 引用组件 taro-ui-vue3 (index.esm.js) 引用组件
    dev:weapp 3386 KB 3167 KB
    build:weapp 1363 KB 1348 KB
  • 以一个只有两个页面、分别引用了AtAccordionAtButtonAtFlexAtFlexItemAtAvatar 的 Demo 小程序为例

    编译命令 taro-ui-vue3/lib 引用组件 taro-ui-vue3 (index.esm.js) 引用组件
    dev:weapp 837 KB 1204 KB
    build:weapp 248 KB 404 KB

备注

  • 以上数据来源于微信开发工具 详情 -> 基本信息 -> 本地代码
  • build 配置使用 Taro 默认编译配置

@b2nil

This comment has been minimized.

@b2nil b2nil removed the enhancement New feature or request label Dec 5, 2020
@b2nil b2nil unpinned this issue Oct 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant