前端架构: 脚手架开发流程中的难点梳理

脚手架的开发流程


1 )开发流程

  • 创建 npm 项目
  • 创建脚手架入口文件,最上方添加:
    • #!/usr/bin/env node
  • 配置 package.json, 添加 bin 属性
  • 编写脚手架代码
  • 将脚手架发布到 npm

2 )使用流程

  • 安装脚手架

    • npm install -g your-own-cli
  • 使用脚手架

    • your-own-cli

3 )脚手架开发难点

  • 分包: 将复杂的系统拆分成若干个模块,并且合并成一个复杂系统
  • 命令注册,如:
    • $ vue create
    • $ vue add
    • $ vue invoke
    • 这里需要了解,如何注册命令,以及执行命令
  • 参数解析
    • 如:vue command [options]
    • options全称: --version, --help
    • options简写:-V, -h
    • 带params的options: --path /Users/xxx/…/vue-test
    • 帮助文档:
      • global help 是指对主命令进行帮助
        • Usage
        • Options
        • Commands
      • vue的帮助文档示例,这个属于 global help
        $ vue
        Usage: vue  [options]
        
        Options:
          -V, --version                              output the version number
          -h, --help                                 output usage information
        
        Commands:
          create [options]                 create a new project powered by vue-cli-service
          add [options]  [pluginOptions]     install a plugin and invoke its generator in an already created project
          invoke [options]  [pluginOptions]  invoke the generator of a plugin in an already created project
          inspect [options] [paths...]               inspect the webpack config in a project with vue-cli-service
          serve [options] [entry]                    serve a .js or .vue file in development mode with zero config
          build [options] [entry]                    build a .js or .vue file in production mode with zero config
          ui [options]                               start and open the vue-cli ui
          init [options]