Skip to content

Commit 5227564

Browse files
committed
自动构建文档
1 parent 98bb024 commit 5227564

File tree

9 files changed

+126
-1
lines changed

9 files changed

+126
-1
lines changed

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# 编译环境
2+
language: node_js
3+
4+
# Node 版本
5+
node_js:
6+
- "10"
7+
8+
# 安装依赖
9+
install:
10+
- npm install
11+
12+
# 代码编译
13+
script:
14+
- npm run build
15+
- npm run release
16+
17+
# 发布配置
18+
deploy:
19+
# 发布到 gh-pages
20+
- provider: pages
21+
local_dir: dist
22+
skip_cleanup: true
23+
github_token: $GITHUB_TOKEN
24+
keep_history: true
25+
on:
26+
branch: master
27+
# 发布到 npm
28+
- provider: npm
29+
email: $NPM_EMAIL
30+
api_key: $NPM_TOKEN
31+
skip_cleanup: true
32+
on:
33+
tags: true
34+
branch: master

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,92 @@ module.exports = {
554554
6. 浏览器访问
555555

556556
![代码示例](site/images/vue-snippet-01.png)
557+
558+
## Travis 自动构建
559+
560+
1. `Github` 授权配置 [https://github.com/settings/tokens](https://github.com/settings/tokens) 并且记录 `GITHUB_TOKEN` 的值
561+
562+
![GITHUB_TOKEN](site/images/vue-github-01.png)
563+
564+
2. `NPM` 创建一个 `token` 授权码,记录该授权码
565+
566+
![NPM_TOKEN](site/images/vue-npm-01.png)
567+
568+
3. `githbub` 授权访问 [https://www.travis-ci.org](https://www.travis-ci.org/)
569+
570+
![Travis 开启项目](site/images/vue-travis-01.png)
571+
572+
4. Travis 环境变量设置
573+
574+
| 变量 | 描述 |
575+
| :----------- | :---------------------- |
576+
| GITHUB_TOKEN | Github 生成的授权 Token |
577+
| NPM_EMAIL | NPM 注册邮箱 |
578+
| NPM_TOKEN | NPM 授权 Token |
579+
580+
![Travis 环境变量](site/images/vue-travis-02.png)
581+
582+
5. 构建配置文件 `.travis.yml` 具体配置参考 [https://docs.travis-ci.com](https://docs.travis-ci.com)
583+
584+
```yml
585+
# 编译环境
586+
language: node_js
587+
588+
# Node 版本
589+
node_js:
590+
- "10"
591+
592+
# 安装依赖
593+
install:
594+
- npm install
595+
596+
# 代码编译
597+
script:
598+
- npm run build
599+
- npm run release
600+
601+
# 发布配置
602+
deploy:
603+
# 发布到 gh-pages
604+
- provider: pages
605+
local_dir: dist
606+
skip_cleanup: true
607+
github_token: $GITHUB_TOKEN
608+
keep_history: true
609+
on:
610+
branch: master
611+
# 发布到 npm
612+
- provider: npm
613+
email: $NPM_EMAIL
614+
api_key: $NPM_TOKEN
615+
skip_cleanup: true
616+
on:
617+
tags: true
618+
branch: master
619+
```
620+
621+
6. 项目构建 `vue.config.js`
622+
623+
```javascript
624+
// vue.config.js 部署路径调整
625+
...
626+
publicPath: process.env.NODE_ENV !== "production" ? "/" : "/vue-ui-docs",
627+
...
628+
```
629+
630+
```javascript
631+
// site/router/index.js 路由调整
632+
...
633+
base: process.env.NODE_ENV !== "production" ? "/" : "/vue-ui-docs",
634+
...
635+
```
636+
637+
7. `package.json` 添加 `script` 打包发布指令
638+
639+
```javascript
640+
...
641+
"release": "vue-cli-service build --dest lib --target lib src/index.js",
642+
...
643+
```
644+
645+
8. 提交代码自动构建

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"serve": "vue-cli-service serve",
77
"build": "vue-cli-service build",
8+
"release": "vue-cli-service build --dest lib --target lib src/index.js",
89
"lint": "vue-cli-service lint"
910
},
1011
"dependencies": {

site/images/vue-github-01.png

210 KB
Loading

site/images/vue-npm-01.png

89 KB
Loading

site/images/vue-travis-01.png

164 KB
Loading

site/images/vue-travis-02.png

184 KB
Loading

site/router/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const routes = [
3535

3636
const router = new VueRouter({
3737
mode: "history",
38-
base: process.env.BASE_URL,
38+
base: process.env.NODE_ENV !== "production" ? "/" : "/vue-ui-docs",
3939
routes
4040
});
4141

vue.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
publicPath: process.env.NODE_ENV !== "production" ? "/" : "/vue-ui-docs",
23
pages: {
34
index: {
45
// 入口文件

0 commit comments

Comments
 (0)