Code Monkey home page Code Monkey logo

vue-cli-plugin-register-component's Introduction

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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.