Skip to content

Commit e122f9e

Browse files
committed
重新提交文档项目
1 parent 98320fd commit e122f9e

File tree

2,583 files changed

+285924
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,583 files changed

+285924
-0
lines changed

.github/workflows/algolia.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: algolia
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
algolia:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- name: Get the content of algolia.json as config
12+
id: algolia_config
13+
run: echo "config=$(cat crawlerConfig.json | jq -r tostring)" >> $GITHUB_OUTPUT
14+
- name: Push indices to Algolia
15+
uses: signcl/docsearch-scraper-action@main
16+
env:
17+
APPLICATION_ID: ${{ secrets.APPLICATION_ID }}
18+
API_KEY: ${{ secrets.API_KEY }}
19+
CONFIG: ${{ steps.algolia_config.outputs.config }}

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.DS_Store
2+
node_modules
3+
4+
scripts/docsearch-scraper
5+
6+
# 缓存
7+
docs/.vitepress/cache
8+
docs/.vitepress/.temp
9+
docs/.vitepress/dist
10+
11+
# local env files
12+
.env.local
13+
.env.*.local
14+
15+
# Log files
16+
npm-debug.log*
17+
yarn-debug.log*
18+
yarn-error.log*
19+
20+
# Editor directories and files
21+
.idea
22+
.vscode
23+
*.suo
24+
*.ntvs*
25+
*.njsproj
26+
*.sln
27+
*.sw?

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 muyaCode
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# FrontEndLearnNotes/前端学习笔记
2+
3+
**vitepress 框架的 markdown 写作相关文档**<https://vitepress.vuejs.org/guide/markdown>
4+
5+
## 前端学习笔记
6+
7+
记录大前端和全栈的学习笔记 + 学习路径 + 各种网站和学习资源。
8+
9+
## 运行 VitePress 文档项目
10+
11+
使用 npm / yarn / pnpm / bun /等包管理都行
12+
13+
⚠️ 注意:一个前端项目从安装依赖起,从头到尾,尽量只使用一个包管理器,否则会出现乱七八糟的错误。
14+
15+
以下以 bun 包管理 为例:
16+
17+
1. 安装依赖
18+
19+
```bash
20+
bun i
21+
```
22+
23+
2. 运行文档项目
24+
25+
```bash
26+
bun docs:dev
27+
```
28+
29+
3. 打包文档项目
30+
31+
```bash
32+
bun docs:build
33+
```
34+
35+
4. 基于 main 分支打包并提交到远程仓库部署 git-pages,原理是运行项目根目录的脚本文件`deploy.sh` ,命令:
36+
37+
```bash
38+
bun run deploy
39+
```
40+
41+
如果报错,则去检查修改 `deploy.sh` 脚本,把包管理命令、仓库地址等改成你自己的配置
42+
43+
## 解决 JavaScript/Node 项目打包内存溢出报错:JS stacktrace
44+
45+
安装依赖后,运行或打包项目报错:vitepress 内存溢出(JS stacktrace),JavaScript 堆内存不足的错误。这在打包大型 VitePress 项目时很常见,因为 Node.js 默认的内存限制比较小。
46+
47+
你遇到的是 JavaScript 堆内存不足的错误。这在打包大型 VitePress 项目时很常见,因为 Node.js 默认的内存限制比较小。下面是几种解决方案:
48+
49+
### 1. 增加 Node.js 堆内存限制
50+
51+
在执行打包命令时,通过 `NODE_OPTIONS` 环境变量增加内存限制:
52+
53+
```bash
54+
NODE_OPTIONS=--max-old-space-size=8192 vitepress build docs
55+
```
56+
57+
你可以根据需要调整 `8192`(即 8GB)这个值。
58+
59+
### 2. 修改 package.json 脚本
60+
61+
`package.json` 中修改打包脚本,永久增加内存限制:
62+
63+
```json
64+
{
65+
"scripts": {
66+
"docs:build": "NODE_OPTIONS=--max-old-space-size=8192 vitepress build docs"
67+
}
68+
}
69+
```
70+
71+
以上如果报错,设置环境变量的语法各个系统中不同,以下是针对不同环境的解决方案:
72+
73+
#### 跨平台解决方案(推荐)
74+
75+
使用 `cross-env` 包来统一不同操作系统的环境变量设置语法。
76+
77+
1. 安装 `cross-env`
78+
79+
```bash
80+
bun install --save-dev cross-env
81+
```
82+
83+
2. 修改 `package.json` 中的脚本:
84+
85+
```json
86+
{
87+
"scripts": {
88+
"docs:build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vitepress build docs"
89+
}
90+
}
91+
```
92+
93+
#### 仅针对 Windows 的解决方案
94+
95+
如果你确定只在 Windows 环境下开发,可以使用 Windows 专用的环境变量设置语法:
96+
97+
```json
98+
{
99+
"scripts": {
100+
"docs:build": "set NODE_OPTIONS=--max-old-space-size=8192 && vitepress build docs"
101+
}
102+
}
103+
```
104+
105+
#### 同时支持 Windows 和 Unix 系统
106+
107+
如果你需要同时支持 Windows 和 Unix 系统,可以使用以下方法:
108+
109+
```json
110+
{
111+
"scripts": {
112+
"docs:build:win": "set NODE_OPTIONS=--max-old-space-size=8192 && vitepress build docs",
113+
"docs:build:unix": "NODE_OPTIONS=--max-old-space-size=8192 vitepress build docs",
114+
"docs:build": "npm run docs:build:win || npm run docs:build:unix"
115+
}
116+
}
117+
```
118+
119+
#### 终极解决方案:使用配置文件
120+
121+
如果你不想修改 `package.json`,可以创建一个 `.env` 文件并添加:
122+
123+
```env
124+
NODE_OPTIONS=--max-old-space-size=8192
125+
```
126+
127+
然后使用支持加载环境变量的工具来运行 VitePress,例如 `dotenv-cli`
128+
129+
```bash
130+
bun install --save-dev dotenv-cli
131+
```
132+
133+
修改 `package.json`
134+
135+
```json
136+
{
137+
"scripts": {
138+
"docs:build": "dotenv -e .env vitepress build docs"
139+
}
140+
}
141+
```
142+
143+
### 验证内存限制是否生效
144+
145+
可以添加一个简单的脚本验证内存限制是否生效:
146+
147+
```json
148+
{
149+
"scripts": {
150+
"check-memory": "node -p 'process.memoryUsage().heapTotal / 1024 / 1024'"
151+
}
152+
}
153+
```
154+
155+
运行 `bun run check-memory` 应该看到接近你设置的值(以 MB 为单位)。
156+
157+
### 3. 优化 VitePress 配置
158+
159+
通过配置 Vite 来优化打包过程:
160+
161+
```javascript
162+
// .vitepress/config.js
163+
export default {
164+
vite: {
165+
build: {
166+
// 调整 chunk 大小警告限制(可选)
167+
chunkSizeWarningLimit: 1000, // 1MB
168+
169+
// 配置 Rollup 分块策略
170+
rollupOptions: {
171+
output: {
172+
manualChunks(id) {
173+
// 将大依赖单独分块
174+
if (id.includes("node_modules")) {
175+
return id
176+
.toString()
177+
.split("node_modules/")[1]
178+
.split("/")[0]
179+
.toString();
180+
}
181+
},
182+
},
183+
},
184+
},
185+
},
186+
};
187+
```
188+
189+
### 4. 分步构建(高级)
190+
191+
对于超大型项目,可以考虑使用 Vite 的库模式进行分步构建,但这需要更复杂的配置。
192+
193+
### 最终建议
194+
195+
先尝试第一种方法,如果仍然报错,再结合修改 `package.json` 和优化配置。如果项目特别大,可能需要考虑重构部分代码或使用动态导入来拆分应用。

0 commit comments

Comments
 (0)