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