收藏
回答

【开发工具死循环】使用gulp构建引发开发者工具死循环(180712版本特有)

框架类型 问题类型 操作系统 工具版本
小程序 Bug macOS 180712

我们的小程序是使用gulp构建的(src目录->dist目录,开发者工具使用dist目录),每次一执行gulp命令开发工具就会提示死循环,这是180712版本新出现的问题,180612版本正常。




回答关注问题邀请回答
收藏

1 个回答

  • HS
    HS
    2018-07-13

    1、工具是在 project.config.json 指定的 dist 目录,还是直接使用 dist 目录呢?

    2、gulp 是否有 watch 呢,还是构建完毕即退出了

    3、编辑设置里,是否有开启保存时自动编译等选项呢

    2018-07-13
    有用
    回复 8
    • 张博 Bill
      张博 Bill
      2018-07-13
      1. 直接使用了dist目录,未编辑过project.config.json

      2. 有加watch,watch延迟200ms



      2018-07-13
      回复
    • 张博 Bill
      张博 Bill
      2018-07-13

      这个问题有可能跟我们文件多有关系吗?大概600-700个文件,我是固态硬盘



      2018-07-13
      回复
    • HS
      HS
      2018-07-13回复张博 Bill

      尝试去掉 “编译时自动保存所有文件” 试试呢

      2018-07-13
      回复
    • 张博 Bill
      张博 Bill
      2018-07-16回复HS

      不起作用。有个现象很奇怪只有第一次执行gulp命令时会这样;当进入watch状态后修改文件,就没事,我的gulp脚本我可以贴一下


      难道是我任务里的“clean”导致的?


      'use strict';
      /**
       * Created by ZhangBo on 2018/04/11.
       */
      const colors = require('colors');
       
      const gulp = require("gulp");
      const watch = require("gulp-watch");
      const clean = require('gulp-clean');
      const prune = require('gulp-prune');
      const changed = require('gulp-changed');
      const minimist = require('minimist');
      const replace = require('gulp-replace');
      const filter = require('gulp-filter');
      const gulpIgnore = require('gulp-ignore');
      const debug = require('gulp-debug');
      const smushit = require('gulp-smushit');
      const gulpif = require('gulp-if');
      const rename = require('gulp-rename');
       
      const decompress = require('gulp-decompress');
      const request = require('request');
      const source = require('vinyl-source-stream')
       
      const runSequence = require('run-sequence');
      const merge = require('merge-stream');
       
      const _ = require('lodash');
       
      const changjiangConfigFile = require('./config-changjiang.json');
      const commonConfigFile = require('./config-common.json');
      const saasConfigFile = require('./config-saas.json');
       
      let configFile;
       
      //product参数默认值
      const knownOptions = {
        string: 'product',
        default: { product: 'timerbox' }
      };
      //解析product参数,以及是否有--clean-images参数
      const options = minimist(process.argv.slice(2), knownOptions);
       
      if (options.product == 'changjiang') {
        configFile = changjiangConfigFile;
      } else if (options.product == 'common') {
        configFile = commonConfigFile;
      } else if (options.product == 'saas') {
        configFile = saasConfigFile;
      } else {
        configFile = commonConfigFile;
      }
       
      //源目录
      const srcFolder = {
        jsFile: "src/**/*.js",
        wxmlFile: "src/**/*.wxml",
        wxssFile: "src/**/*.wxss",
        jsonFile: "src/**/*.json",
        imagesFile: [
          "src/**/*.jpg",
          "src/**/*.gif",
          "src/**/*.png",
          "src/**/*.bmp",
        ]
      };
      //目标目录
      var distFolder = `dist-${options.product}`;
       
      const patternReg = /\[\[\w+\]\]/g;
       
      let isRelease = false;
      if (options.release) {
        isRelease = true;
        distFolder += '-release'
      }
       
      configFile.strings.IS_RELEASE = isRelease;
       
      //清理dist目录的任务
      gulp.task('clean', function () {
        let cleanDist = gulp.src([distFolder + "/*", "!" + distFolder + "/project.config.json"], { read: false })
          .pipe(clean());
        // 清理src/packages目录
        let cleanPackages = gulp.src(["src/packages"], { read: false }).pipe(clean());
        return merge(cleanDist, cleanPackages);
      });
       
      console.log(configFile.strings);
       
      //主任务
      gulp.task('doTask', function () {
        const replaceFunction = function (match) {
          let key = match.substring(2, match.length - 2);
          return configFile.strings[key] || match;
        };
       
        let jsStream = gulp.src([srcFolder.jsFile])
          .pipe(prune({
            dest: distFolder,
            ext: ['.js'],
            verbose: true
          }))
          .pipe(replace(patternReg, replaceFunction))
          .pipe(changed(distFolder, {
            hasChanged: changed.compareContents
          }))
          .pipe(gulp.dest(distFolder));
       
        let wxmlStream = gulp.src(srcFolder.wxmlFile)
          .pipe(prune({ dest: distFolder, ext: ['.wxml'] }))
          .pipe(replace(patternReg, replaceFunction))
          .pipe(changed(distFolder, {
            hasChanged: changed.compareContents
          }))
          .pipe(gulp.dest(distFolder));
       
        let wxssStream = gulp.src([srcFolder.wxssFile])
          .pipe(prune({
            dest: distFolder,
            ext: ['.wxss']
          }))
          .pipe(replace(patternReg, replaceFunction))
          // .pipe(changed(distFolder))
          .pipe(gulp.dest(distFolder));
       
        let jsonStream = gulp.src([srcFolder.jsonFile])
          .pipe(prune({
            dest: distFolder,
            ext: '.json'
          }))
          .pipe(replace(patternReg, replaceFunction))
          .pipe(changed(distFolder, {
            hasChanged: changed.compareContents
          }))
          .pipe(gulp.dest(distFolder));
       
        let imagesStream = gulp.src(srcFolder.imagesFile)
          .pipe(prune({ dest: distFolder, ext: ['.png', '.jpg', '.gif'] }))
          .pipe(changed(distFolder))
          .pipe(gulpif(!!options['zip-image'], smushit({
            verbose: true
          })))
          .pipe(gulp.dest(distFolder));
       
        return merge(jsStream, wxmlStream, wxssStream, jsonStream, imagesStream);
      });
       
      gulp.task("watch", function (callback) {
        watch('src/**/*', { debounceDelay: 200 }, function (vinyl) {
          gulp.start("doTask", callback);
        });
      });
       
      gulp.task("clean-reference", function (callback) {
        return gulp.src("src/nodemodules", { read: false })
          .pipe(clean());
      });
       
      gulp.task('default', function (callback) {
        runSequence('clean', 'clean-reference', 'doTask', 'watch', callback);
      });
       
      //gulp新建文件
       
      gulp.task('new-component', function (callback) {
        let path = options.path;
        if (!path) {
          callback('no paramter path');
          return;
        }
        let spitIndex = path.lastIndexOf('/');
        let fileName = path.substring(spitIndex + 1);
       
        return gulp.src('templates/component-master.tar.gz')
          .pipe(decompress({ strip: 1 }))
          .pipe(debug({ title: 'decompress:' }))
          .pipe(rename(function (renamePath) {
            if (renamePath.basename == 'component') {
              renamePath.basename = fileName;
            }
          }))
          .pipe(debug())
          .pipe(gulp.dest(`src/${path}/`));
        // return request('http://gitlab.vlife.com/mini-program/templates/component/-/archive/master/component-master.tar.gz')
        //   .pipe(source('component-master.tar.gz'))
        //   .pipe(debug({ title: 'source:' }))
        //   .pipe(decompress({ strip: 1 }))
        //   .pipe(debug({ title: 'decompress:' }))
        //   .pipe(rename(function (renamePath) {
        //     renamePath.basename = fileName;
        //   }))
        //   .pipe(debug())
        //   .pipe(gulp.dest(`src/${path}/`));
      })


      2018-07-16
      回复
    • HS
      HS
      2018-07-16回复张博 Bill

      是否是有删除工具正在使用的 dist 目录呢?如果是的话,是有可能出现问题的,因为这个节点的删除工具有可能无法捕获到。建议工具直接在根目录建立项目,然后使用 project.config.json 指定 dist 目录为 miniprogramRoot,一样可以达到效果哦

      2018-07-16
      回复
    查看更多(3)
登录 后发表内容