1. 程式人生 > >如何建立併發佈一個 vue 元件

如何建立併發佈一個 vue 元件

步驟

建立 vue 的腳手架


npm install -g @vue/cli
vue init webpack

繫結 git 專案


cd existing_folder
git init
git remote add origin http://gitlab.alipay-inc.com/ampg/my-projec.git
git add .
git commit
git push -u origin master

寫元件

建立元件 src/components/xxx.vue

例如:


<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h2>Essential Links</h2>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
</style>

釋出


npm publish

程式碼參考

  1. vue-component-popup

參考文件

  1. Packaging Vue Components for npm
  2. Vue CLI 3
  3. vue-sfc-rollup

原文地址:https://segmentfault.com/a/1190000016945983