简体   繁体   English

Vue 自定义(cli ?)项目生成器

[英]Vue custom (cli ?) project generator

All my VueJS projects use at the beginning the same baseline :我所有的 VueJS 项目一开始都使用相同的基线:

  • Vuex Vuex
  • Vue Router Vue路由器
  • Immutable.js不可变的.js
  • MathJS数学JS
  • MomentJs MomentJs
  • ChartJS图表JS

Plus, all my projects have quite the same "index.js" file.另外,我所有的项目都有完全相同的“index.js”文件。

Is there a way to have a command line (preferably based on Vue CLI) that can generate a project with a pre-coded "index.js" file and a package.json with those above dependencies ?有没有办法让命令行(最好基于 Vue CLI)生成一个带有预编码“index.js”文件和具有上述依赖项的 package.json 的项目?

It sounds like you are wanting to use the Vue CLI to create a project.听起来您想使用Vue CLI创建一个项目。 However, you additionally want some default npm packages to be installed and imported into your index.js file.但是,您还需要安装一些默认的 npm 包并将其导入到您的index.js文件中。

Answer: no.回答:没有。 this functionality does not exist (currently)此功能不存在(当前)

Some Suggestions:一些建议:

  1. Open a feature request here .在此处打开功能请求。 If you did do a feature request, you should descibe it in a more general way.如果你确实做了一个功能请求,你应该用更一般的方式来描述它。 For example 'allow the ability to specify npm packages on project creation' opposed to specifically installing ChartJS, Moment and the other ones.例如,“允许在项目创建时指定 npm 包的能力”,而不是专门安装 ChartJS、Moment 和其他。 That's too specific, that will get shot down and closed in a heart beat.这太具体了,它会被击落并在心跳中关闭。
  2. Create a repo with the project structure and packages you want and always start from that repo (opposed to using vue cli)使用您想要的项目结构和包创建一个 repo,并始终从该 repo 开始(反对使用 vue cli)
  3. Write your own custom node cli to interface with vue cli that handels your extra steps for you.编写您自己的自定义节点 cli 以与 vue cli 接口,该 cli 为您处理额外的步骤。 You could easily write a node (console program) that executes the steps you want.您可以轻松编写一个节点(控制台程序)来执行您想要的步骤。 Basically, create the vue project, npm install what you need, generate an index.js with your package imports.基本上,创建 vue 项目,npm install 你需要的东西,用你的包导入生成一个 index.js。

I think the easiest route is to just create an empty vue project how you want it.我认为最简单的方法是按照你想要的方式创建一个空的 vue 项目。 Save that repo as 'vue-boilerplate' or something and just always start off with that empty project opposed to doing vue create every time.将该存储库另存为“vue-boilerplate”或其他内容,然后始终从该空项目开始,而不是每次都执行vue create

In my personal opinion, I think going through all this to npm install 3 packages and add the imports to a js file isn't entirely worth it unless you find yourself creating a massive amount of projects that will all require the exact same setup.在我个人看来,我认为通过 npm install 3 个包并将导入添加到 js 文件中并不完全值得,除非您发现自己创建了大量需要完全相同设置的项目。

Angular has a similar idea called schematics but I do not see an equivilant within Vue as of yet. Angular 有一个类似的想法,称为原理图,但我在 Vue 中还没有看到等价物。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM