前段工程化脚手架工具(一)

132 阅读1分钟

内容概要:

1.脚手架的作用

2.常用的脚手架工具

3.通用脚手架工具剖析

4.开发一款脚手架

脚手架的本质作用

创建项目基础结构,提供项目规范和约定,相同的组织结构,开发范式,模块依赖,工具配置,基础代码, 使用脚手架工具快速搭建特定类型的项目骨架,然后基于这个骨架进行后续的开发工作。举例子:IDE创建项目的过程就是一个脚手架的工作流程。 前端技术选型比较多样,也没有统一的标准。

所以前端脚手架不会集成在摸个IDE当中,都是以一个独立的工具存在。

常用的脚手架工具

根据信息创建对应的项目基础结构:

React项目 -> create-react-app

Vue.js项目 -> vue-cli

Angular项目 -> angular-cli

通用脚手架工具:Yeoman, Plop

例如创建一个组建/ 模块化需要的文件

重点关注几个有代表性的工具

Yeoman

Yeoman官网:yeoman.io/

概述:Yeoman is a generic scaffolding system allowing the creation of any kind of app. It allows for rapidly getting started on new projects and streamlines the maintenance of existing projects. 使用场景:

  • Rapidly create a new project
  • Create new sections of a project, like a new controller with unit tests
  • Create modules or packages
  • Bootstrapping new services
  • Enforcing standards, best practices and style guides
  • Promote new projects by letting users get started with a sample app
  • Etc, etc

安装: npm install -g yo

//查看node,npm,yarn是否安装,查看版本

node -v, npm -v, yarn -v

优缺点

优点:搭配不同的generator创建任何类型的项目,可以通过自定义generator创建自己的前端脚手架

缺点:过于通用,不够专注


未完待续