forked from imooc-lego/students-learn-task
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhangyuan
committed
Jul 7, 2021
1 parent
8d6e639
commit 93acb5a
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
**脚手架原理,执行过程** | ||
> 以vue-cli 为例 | ||
- 脚手架本质是一个操作系统的客户端 | ||
- which vue 可以查看到 vue执行的地址 | ||
- 执行vue 是执行node下bin目录下的vue | ||
- vue只是个超链接,对应的是一个node项目文件 | ||
- vue: 执行 node目录下 lib/node_modules/@vue/cli/bin/vue.js | ||
- node目录下 lib/modules 是node全局依赖, npm -g执行的安装都会在这个目录下 | ||
- 最后终端用 node执行了 vue.js | ||
- vue.js 解析出 command 和 options, 并执行command, 执行完毕退出 | ||
|
||
|
||
|
||
#### 执行文件 | ||
#!/usr/bin/env node | ||
规定脚本文件用什么执行 | ||
由于脚本解释器被安装在系统的不同目录下,env指定去系统的 PATH目录下查找, env还规定了一些系统环境变量 | ||
|
||
|
||
#### 本地调试(方法一) | ||
npm link 进行本地调试(创建软链接), 效果与npm publish一样, 不需要频繁发布; | ||
|
||
|
||
本地调试步骤 | ||
1、在lib内创建软链接,npm link | ||
2、在使用的包内, 引用软链接 npm link xxx(lib) | ||
3、由于lib未发布到npm上,需要手动指定dependencies | ||
|
||
|
||
#### 创建软链接 | ||
ln -s 创建软链接 | ||
|
||
|
||
ln -s 文件地址 命令别名 | ||
|
||
|
||
例如 在node的bin目录执行 ln -s /xxxx/test.js test | ||
|
||
|
||
test.js文件 需要 #!/usr/bin/env node 指定执行环境 | ||
|
||
|
||
#### lerna | ||
|
||
|
||
lerna是一个优化基于git+npm的多packages项目的管理工具 | ||
|
||
|
||
lerna create <package_name> 创建packages 并初始化 | ||
|
||
|
||
lerna add <> 默认为所有的packages添加npm依赖, 也可指定单独package | ||
|
||
|
||
lerna clean 清楚依赖, 也可指定 | ||
|
||
|
||
lerna bootstrap 重装依赖 | ||
|
||
|
||
lerna link 创建依赖软链接, 相当于 npm link <package_name> , npm这个工作量太巨大了, 而且容易出错 | ||
|
||
|
||
lerna exec -- rm -rf node_modules 执行上下文不是当前目录, 二是packages下的每一个package | ||
|
||
|
||
lerna exec --scope @yyds-cli/core -- rm -rf node_modules scope指定包, 需要带上group | ||
|
||
|
||
lerna run test 与npm run 一致, 只是批量执行packages下每个包 指定同样是 --scope 包名 | ||
|
||
|
||
lerna publish | ||
|
||
|
||
警告, 添加文件 LICENSE.md | ||
|
||
|
||
报错,需要把私有变为共有, 在每个包内的package.json添加 | ||
`"publishConfig": {"access": "public"}` | ||
|
||
|
||
|
||
`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
## 第一周 | ||
- [01-Week01-技术设计文档](01-Week01-技术设计文档.md) | ||
- [02-Week02-脚手架学习笔记](02-Week02-脚手架学习笔记.md) |