auto create .vue file by shell command 經過終端自動建立vue文件css
1: 咱們在寫xxx.vue
頁面文件的時候,通常都要寫這些重複的代碼:vue
<template>
<div class="zlj-comp-ct">
zlj組件
</div>
</template>
<script>
export default {
name: 'zlj'
}
</script>
<style lang="scss" scoped>
.zlj-comp-ct {
}
</style>
複製代碼
2:寫組件的時候可能還要在components
目錄下面新建一個目錄:xxx,裏面是xxx.vue和index.jsgit
好比myForm組件github
// myForm.vue
<template>
<div class="myForm-comp-ct">
myForm組件
</div>
</template>
<script>
export default {
name: 'myForm'
}
</script>
<style lang="scss" scoped>
.myForm-comp-ct {
}
</style>
// index.js
import myForm from './myForm.vue'
export default myForm
複製代碼
每次都寫這些代碼,是否是很煩?shell
npm install auto-vue-file -g
複製代碼
auto-vue-file -c
複製代碼
名稱 | 說明 | 使用例子 |
---|---|---|
component | 建立一個vue組件, 默認在components目錄下面 | auto-vue-file -c 或 auto-vue-file --component |
page | 建立一個vue組件,默認在views目錄 | auto-vue-file -p 或 auto-vue-file --page |
path | 在指定目錄建立vue組件,須要提供-c或-p參數 | auto-vue-file -c --path ./src/haha 或 auto-vue-file -p --path ./src/haha |
你也能夠使用本身的vue模版文件,文件名爲auto-vue-file.template.js,存放在項目根目錄下面,內容以下npm
// template.js you can generate
// auto-vue-file.template.js
module.exports = {
vueTemplate: componentName => {
return `<template>
<div class="${componentName}-comp-ct">
${componentName}組件
</div>
</template>
<script>
export default {
name: '${componentName}'
}
</script>
<style lang="scss" scoped>
.${componentName}-comp-ct {
}
</style>
`
},
entryTemplate: componentName => {
return `import ${componentName} from './${componentName}.vue'
export default ${componentName}`}
}
複製代碼
你也能夠執行bash
auto-vue-file --init
複製代碼
自動生成該配置文件:auto-vue-file.template.jspost
而後改爲你本身須要的樣子。ui
參考:juejin.im/post/5c4a6f…spa