1.安装npm
yum  -y  install  npm
2.配置npm仓
npm config set registry https://mirrors.tencent.com/npm/
3.安装gitbook-cli和gitbook
npm install gitbook-cli -g
npm install gitbook -g
查看是否安装成功:gitbook -V

4.编译book
进入到book工程根目录,执行:gitbook build
5.启动服务gitbook serve
工程目录下执行:gitbook serve ./ --port=80
其中,--port指定端口,默认是4000
6.问题汇总
1.安装gitbook-cli时,报错TypeError: cb.apply is not a function,报错截图如下:

原因:graceful-fs兼容问题
解决办法:进入到报错提示里的目录,我这边是进入到/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/,执行npm install graceful-fs@latest --save,安装最新的graceful-fs
2.执行build时报错,TypeError: Cannot read property 'pipes' of undefined,报错截图如下:

原因:graceful-fs兼容问题
解决办法:同问题1,将版本指定到4.2.0(应该是某些版本有问题而已)npm install graceful-fs@4.2.0 --save
强烈建议:文件名不要有中文,尽量不要用特殊字符,避免踩坑
7.初始化脚本
- #!/bin/bash
- # 找不到则安装
- if ! which gitbook > /dev/null 2>&1; then
-     echo "start init."
-     # 安装npm
-     yum  -y  install  npm
-     # 配置npm源
-     npm config set registry https://mirrors.tencent.com/npm/
-     # 安装gitbook-cli和gitbook
-     npm install gitbook-cli -g
-     npm install gitbook -g
-     # 解决版本兼容
-     if which gitbook > /dev/null 2>&1; then
-         # npm依赖包安装路径
-         node_modules_path=$(npm root -g)
-         cd $node_modules_path/gitbook-cli/node_modules/npm/node_modules/
-         npm install graceful-fs@4.2.0 --save
-         echo "init success."
-     fi
- fi