1、gitbook 脚手架安装

我这里有cnpm就用cnpm了,没有的还是用npm

1
cnpm install -g gitbook-cli

2、初始化 gitbook

新建一个目录

1
gitbook init

在初始化的时候遇到以下问题

1
2
3
TypeError: cb.apply is not a function
at /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18
at FSReqCallback.oncomplete (fs.js:184:5)

查找得知需要修改polyfills.js文件注释掉以下代码

1
2
3
fs.stat = statFix(fs.stat)
fs.fstat = statFix(fs.fstat)
fs.lstat = statFix(fs.lstat)

注释掉再执行gitbook的初始化后又出现了其它问题

1
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Promise

查了一下,需要降级node.js的版本,我这里是14的版本,这里我们降回12.22.9版本,

地址:

https://nodejs.org/download/release/v12.22.9/node-v12.22.9-x64.msi

再次初始化gitbook,没问题了

3、启动gitbook

1
gitbook serve

4、生成静态页面部署

1
gitbook build

在目录下会生成_book目录,接下来部署就好

\