plugin-copy-component

Taro复制组件插件

Usage no npm install needed!

<script type="module">
  import pluginCopyComponent from 'https://cdn.skypack.dev/plugin-copy-component';
</script>

README

@tarojs/plugin-copy-component

Taro复制组件插件

安装

在 Taro 项目根目录下安装

yarn add @tarojs/plugin-copy-component
# OR
$ npm install @tarojs/plugin-copy-component --save

使用

引入插件

请确保 Taro CLI 已升级至 Taro 2/3 的最新版本。

修改项目 config/index.js 中的 plugins 配置为如下

const config = {
  ...
  plugins: [
    ...其余插件

    '@tarojs/plugin-copy-component'
  ]
  ...
}

参数

copy-component 插件可以接受如下参数:

/**
 * 复制组件参数
 */
export interface Option {

    /**
     * 源组件路径
     */
    componentsPath: string
}

使用方法

在需要复制的目录新增 components.json 文件,文件格式如下:

/**
 * 组件配置
 */
export interface ComponentConfig{

    /**
     * 源路径
     */
    from:string

    /**
     * 目标路径
     */
    to:string
}

例:

[
    {
        "from": "/componentA",
        "to": "/components"
    },
    {
        "from": "/componentB",
        "to": "/components"
    }
]

这样在 taro build 编译完后就会将 Option.componentsPath 目录下的组件,根据配置复制到 components.json 下的目录。