小程序使用gulp构建,编译前会clean一下dist目录,这时开发者工具报错
发布于 5 年前 作者 xiulandu 13730 次浏览 来自 问答

小程序使用gulp来构建,gulp主要做了以下事情:

  1. 编译less

  2. 复制相关静态文件

  3. watch文件的变化执行相关操作

  4. 其他相关编译

现在每次执行build构建的时候,gulp会clean一下dist目录,这时候开发者工具会报错(概率特别大)提示找不到各种文件,其实文件确实已经被编译出来了,并且重启一下开发者工具问题就解决了,我怀疑是开发者工具文件系统缓存方面的问题,具体报错截图如下:

相关的gulp代码如下:

// 清空dist目录下面的文件
gulp.task('clean', function(cb) {
  return del([`${outputPath}/**`, `!${outputPath}`, `!${outputPath}/readme.md`], cb)
})
 
// copy项目文件到dist目录,使用gulp-changed只复制修改的文件
gulp.task('copy', function() {
  return gulp.src(copyFile)
    .pipe(changed(outputPath))
    .pipe(debug({ title: '正在复制文件:' }))
    .pipe(plumber())
    .pipe(gulp.dest(outputPath))
})
 
// 编译less
gulp.task('less', function() {
  return gulp.src(lessFile)
    .pipe(changed(outputPath, { extension: '.wxss' }))
    .pipe(debug({ title: '正在less文件:' }))
    .pipe(plumber())
    .pipe(less())
    .pipe(rename(function(path) {
      path.extname = '.wxss'
    }))
    .pipe(gulp.dest(outputPath))
})
 
gulp.task('dev', gulp.series('clean', gulp.parallel('copy', 'replace', 'less', 'watch')))
回到顶部