最近我想在做一个hexo,但是我发现hexo是没法同时运行两个预览的,所以,我们可以改改配置文件:package.json(这个是更目录下的)

1.找到这段代码(不出错应该在文首)

{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server"
},

"server": 后面的引号内server后加入-p 端口号

示例:

{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server -p 8888"
},

这里的8888改为你要改的端口号即可

!!!注意📢这里改完后,要换为npm run server

2.改index.js达到改端口的效果:

路径:node_modules\hexo-server\index.js

找到:

  hexo.config.server = Object.assign({
port: 4000,
log: false,
// `undefined` uses Node's default (try `::` with fallback to `0.0.0.0`)
ip: undefined,
compress: false,
header: true
}, hexo.config.server);

修改port后面的东西

示例:

  hexo.config.server = Object.assign({
port: 8888,
log: false,
// `undefined` uses Node's default (try `::` with fallback to `0.0.0.0`)
ip: undefined,
compress: false,
header: true
}, hexo.config.server);

这里的8888改为你要改的端口号即可

!!!注意📢这里改完后,仍旧使用hexo server

大功告成!!!去玩吧~~~