egg.js初始化问题

环境

node版本8.9.0,全局安装了egg-init

操作步骤

我是按照文档走以下命令

$ mkdir egg-example && cd egg-example  
$ npm init egg --type=simple

得到的是一个没有依赖和script的package.json。

{
  "name": "egg",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

请问正确的初始化姿势是?

阅读 3.8k
2 个回答

直接用egg-init而不是npm init egg

查看npm文档,原来还有这种用法:

npm init <initializer>

它会把initializer和create按一定规则拼接,然后交给npx调用,如下:

  • npm init foo->npx create-foo
  • npm init @usr/foo->npx @usr/create-foo
  • npm init @usr->npx @usr/create

并且--参数会交由拼接好的模块调用。所以npm init egg --type=simple 相当于npx create-egg --type=simple

注: create-egg是egg-init的别名包

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题