txw/local-nodemodules/README.md
2026-04-03 14:32:29 +08:00

71 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 本地依赖包说明
本目录存放需要本地调试的依赖包,供各 web 项目通过 `npm link` 方式引用。
## 目录结构
```
local-nodemodules/
└── @cssyq/
└── ggzc-web/ # 工作主页组件库
```
## 首次配置
在项目根目录执行以下命令,将本地包链接到全局:
```bash
# 链接 ggzc-web 到全局
cd local-nodemodules/@cssyq/ggzc-web
npm link
```
## 各 web 项目使用
在项目根目录执行以下命令,创建本地包的 symlink
```bash
# 创建 symlink
for dir in txw-gxzx-web txw-kxtfwzx-web txw-mhzc-web txw-tzzx-web txw-ytzx-web txw-yygl-web; do
mkdir -p $dir/node_modules/@cssyq
rm -rf $dir/node_modules/@cssyq/ggzc-web
ln -sf "$(pwd)/local-nodemodules/@cssyq/ggzc-web" "$dir/node_modules/@cssyq/ggzc-web"
done
```
## 完整安装所有 web 项目依赖
```bash
# 1. 创建 symlink如上
# 2. 安装各项目依赖(使用 --prefer-offline 优先使用本地包)
for dir in txw-gxzx-web txw-kxtfwzx-web txw-mhzc-web txw-tzzx-web txw-ytzx-web txw-yygl-web; do
cd $dir && yarn install --prefer-offline --ignore-engines && cd ..
done
```
## 验证 link 是否成功
```bash
# 检查 link 目标是否正确
ls -la txw-mhzc-web/node_modules/@cssyq/ggzc-web
# 应该显示链接到 local-nodemodules/@cssyq/ggzc-web
# 或者检查包的 version
cat txw-mhzc-web/node_modules/@cssyq/ggzc-web/package.json | grep version
```
## 常见问题
### yarn install 报 @cssyq/ggzc-web not found
需要先创建 symlink 或使用 npm link。yarn 不会自动从 local-nodemodules 查找依赖。
### npm link 后仍然找不到包
确保在对应 web 项目的 `node_modules/@cssyq/` 下有正确的 symlink。npm link 是链接到全局,再在项目中 link 回来。
### 更新本地包后需要重新 link
修改 `local-nodemodules/@cssyq/ggzc-web` 后,不需要重新 link。dist 目录的变动会被直接使用。