Need private packages and team management tools?Check out npm Teams »

@kuaizi/vue-cli-plugin-register-component

1.0.1 • Public • Published

vue-cli-plugin-register-component

参照@vuepress/plugin-register-component

全局组件自动注册

安装

> yarn add @kuaizi/vue-cli-plugin-register-component
# 或者
> npm i @kuaizi/vue-cli-plugin-register-component -D

目录结构

src
  - components
    - componentA
    - componentB
  - pages
    - index
      - components
        _common
          header.vue
          footer.vue
        layout.vue
        _page.vue

默认自动注册 components 目录所有组件, 其中不会注册 _开头的文件或者文件夹

# src/pages/index/components/index.js
import Vue from 'vue'
Vue.component('layout', () => import('./layout.vue'))

使用

# src/app.js
import 'src/components'

new Vue()

多页面

共用

# src/app.js
import './components'

new Vue()

单页

# src/pages/index/main.js
import './components'
// ...

vue-register-component-webpack-plugin

vue组件自动注册

安装

> npm i stall @kuaizi/vue-cli-plugin-register-component

使用

# webpack.config.js
const vueRegisterComponentWebpackPlugin = require('@kuaizi/vue-cli-plugin-register-component')

export default {
  plugins: [
    new vueRegisterComponentWebpackPlugin({
      componentDir: ['./src/components', './src/entries/index/components'],
      // 全局额外组件
      components: [
        { name: 'element', path: './src/additional/element.vue' }
      ]
    })
  ]
}

在入口文件导入自动生成的组件注册文件

-src
  - main.js
  - components
    - index.js // 自动生成

main.js 中导入 components/index.js

# main.js
import './components'

Install

npm i @kuaizi/vue-cli-plugin-register-component

DownloadsWeekly Downloads

67

Version

1.0.1

License

MIT

Unpacked Size

9.47 kB

Total Files

9

Last publish

Collaborators

  • avatar
  • avatar