如何使用 MEAN.IO 生成视图和服务?

How to generate views and services with MEAN.IO?

angular-yeoman 生成器的一个很酷的功能是能够通过命令行创建视图、指令和服务。 MEAN 堆栈是否具有此功能,或者您是否必须将映射手动编码到任何新的依赖项?

我认为这里的一般经验法则是,如果生成器没有用于创建控制器、视图等的子生成器,那么是的,您将不得不手动创建它们。另一种方法是全局安装 angular 生成器,然后继续 运行 它在您的项目中,然后 move/map 相应的文件。您还可以从一些现有的生成器中提取逻辑并将其修改为适合您的项目结构的 move/map 文件。

您可以使用 MEAN.IO 做的是创建自定义包

mean package customPackageName
   create: ./packages/custom/custompackagename
   create: ./packages/custom/custompackagename/app.js
   create: ./packages/custom/custompackagename/package.json
   create: ./packages/custom/custompackagename/bower.json
   create: ./packages/custom/custompackagename/.bowerrc
   create: ./packages/custom/custompackagename/README.md
   create: ./packages/custom/custompackagename/server
   create: ./packages/custom/custompackagename/public
   create: ./packages/custom/custompackagename/public/assets
   create: ./packages/custom/custompackagename/public/assets/css
   create: ./packages/custom/custompackagename/public/assets/css/custompackagename.css
   create: ./packages/custom/custompackagename/public/assets/img
   create: ./packages/custom/custompackagename/public/controllers
   create: ./packages/custom/custompackagename/public/controllers/custompackagename.js
   create: ./packages/custom/custompackagename/public/directives
   create: ./packages/custom/custompackagename/public/routes
   create: ./packages/custom/custompackagename/public/routes/custompackagename.js
   create: ./packages/custom/custompackagename/public/services
   create: ./packages/custom/custompackagename/public/services/custompackagename.js
   create: ./packages/custom/custompackagename/public/views
   create: ./packages/custom/custompackagename/public/views/index.html
   create: ./packages/custom/custompackagename/server
   create: ./packages/custom/custompackagename/server/config
   create: ./packages/custom/custompackagename/server/controllers
   create: ./packages/custom/custompackagename/server/models
   create: ./packages/custom/custompackagename/server/routes
   create: ./packages/custom/custompackagename/server/routes/custompackagename.js
   create: ./packages/custom/custompackagename/server/views
   create: ./packages/custom/custompackagename/server/views/index.html

重新启动 grunt 任务后,在 /#!/custompackagename/example

下可以使用路由

自定义包是一个模块。在该模块中,您加载了在 angular 项目中期望的所有资源。本质上,每个模块都是一个独立的 MEAN 站点。这些模块有一个特定的依赖链。您可以对仅影响此模块的指令、服务、控制器和视图进行自定义。 MEAN.IO 方法创建的代码可重用性更高,但根据项目目标可能会更重一些。我可以看到跨多个 MEAN 包的冗余凉亭或节点依赖项的可能性。

如果您选择删除自定义包,您可以键入

mean uninstall customPackageName

似乎应该有一种方法可以避免一些冗余代码在 mean 包中重用。目前文档和教程有点稀疏。