Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

脚手架开发注意事项 #42

Open
huangshuwei opened this issue May 8, 2020 · 0 comments
Open

脚手架开发注意事项 #42

huangshuwei opened this issue May 8, 2020 · 0 comments

Comments

@huangshuwei
Copy link
Owner

huangshuwei commented May 8, 2020

前言

本文记录脚手架开发中的注意事项。关于脚手架开发可以参考官方文档

npm link

这个命令,在开发脚手架调试阶段中非常有用,可以对开发中的脚手架进行调试。用法是先定位到当前脚手架目录,再执行命令。如:

$ cd /path/my-cli
$ npm link

npm link 相当于在全局安装了此脚手架,你可以在你的全局包中找到此脚手架。
一旦链接到全局,就非常方便了,你只要按照计划调用自己脚手架即可。

注意1
如果测试项目已经安装了此脚手架的某个版本,并且执行脚手架命令是通过 package.json 下的 scripts节点,那么你的调试不会生效,因为优先是先找 node_modules下的脚手架。此时也有办法调试,你只需要不通过package.json 下的 scripts节点调用即可,也就是通过命令行去执行。
注意2
虽然通过npm link 链接到了全局,但是当你链接结束的那一刻,当前脚手架的版本也就确定了,脚手架代码调整,调试也不会跟着生效,你需要重新执行npm link

特别注意 #!/usr/bin/env node

当你脚手架开发完成,进入调试阶段时,可能会出现脚本编译错误信息。windows 环境的错误弹框:
image
此错误信息通过 npm link 后就能重现,而不是等发布到npm 才发现。不出意外应该是入口文件缺少这句 #!/usr/bin/env node。而它的作用是解决了不同的用户node路径不同的问题,可以让系统动态的去查找node来执行你的脚本文件

待续

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant