2

Hexo博客升级随笔

 2 years ago
source link: https://www.iyouhun.com/post-193.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Hexo博客升级随笔 - 游魂博客-分享技术,资源共享
首页 / Hexo博客升级随笔

最近 hexo 博客升级,把遇到的问题做个备份。

由于长时间没同步该博客文章,Jenkins 打包的时候提示

ReferenceError: primordials is not defined

虽然可以发布成功并 push 到远程仓库,但是所有生成的文件内容为空

原因:node 版本过高,gulp 版本过低导致不兼容

解决方式一:

尝试降级node 版本解决 降到 v12之前

解决方式二:

网上找到的,但我用了没解决

使用npm shrinkwrap锁定依赖版本

  • 项目根目录新建npm-shrinkwrap.json
  • npm-shrinkwrap.json内容修改如下:
{
  "dependencies": {
    "graceful-fs": {
        "version": "4.2.2"
     }
  }
}

解决方式三:

前端肯定要探索前沿技术,用新不用旧。那只能升级 gulp

npm install --save-dev [email protected]

但是升级后的 gulp 语法有改动,所以需要修改 gulpfile.js文件,否则会报

TypeError: gulp.on(…).on(…).on(…).on(…).start is not a function
  • gulp.series 用于串行(顺序)执行
  • gulp.parallel 用于并行执行

上面的两个函数接受两个参数:

  • 要执行的任务的名字
  • 需要执行的函数
gulp.task('task1', gulp.series('task1-1', function (done) {
   // task 1 code here
    done();
}));

gulp.task('task2', gulp.series('task2-1', function (done) {
   // task 2 code here
    done();
}));

// Similarly Tasks 3 and 4 Code here

gulp.task('main', gulp.series('task1', 'task2', 'task3', 'task4', function (done) {
    done();
}));

进入官方文档查看,官方的意思是,4.0.0版本的,“default”右边两个参数放在gulp.series()的参数中,否则会报错

// 我的部分 gulp 代码
// 执行task
gulp.task('deploy',gulp.series('minify-css','minify-js',gulp.parallel('rev','minify-html')));

// 部署前代码处理
gulp.task('default',gulp.series(['deploy'],function(e){
  console.log("[complete] please execute: hexo d");
}))

gulp报错gulpInst.start.apply(gulpInst, toRun)

一般是因为gulp cligulp版本不兼容或者没有安装gulp cli导致的

进行全局安装

npm i -g gulp-cli

执行后,报错提示已经存在

此时就需要删除已经安装的版本,重新进行安装

sudo rm /usr/local/bin/gulp
sudo rm /usr/local/share/man/man1/gulp.1
npm i -g gulp-cli

然后执行gulp,可以成功运行。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK