小程序
小游戏
企业微信
微信支付
扫描小程序码分享
我们的小程序是使用gulp构建的(src目录->dist目录,开发者工具使用dist目录),每次一执行gulp命令开发工具就会提示死循环,这是180712版本新出现的问题,180612版本正常。
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
1、工具是在 project.config.json 指定的 dist 目录,还是直接使用 dist 目录呢?
2、gulp 是否有 watch 呢,还是构建完毕即退出了
3、编辑设置里,是否有开启保存时自动编译等选项呢
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
直接使用了dist目录,未编辑过project.config.json
有加watch,watch延迟200ms
这个问题有可能跟我们文件多有关系吗?大概600-700个文件,我是固态硬盘
尝试去掉 “编译时自动保存所有文件” 试试呢
不起作用。有个现象很奇怪只有第一次执行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
'common'
configFile = commonConfigFile;
'saas'
configFile = saasConfigFile;
{
//源目录
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
(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:
})
.pipe(clean());
// 清理src/packages目录
let cleanPackages = gulp.src([
"src/packages"
}).pipe(clean());
return
merge(cleanDist, cleanPackages);
});
console.log(configFile.strings);
//主任务
'doTask'
const replaceFunction =
(match) {
let key = match.substring(2, match.length - 2);
configFile.strings[key] || match;
let jsStream = gulp.src([srcFolder.jsFile])
.pipe(prune({
dest: distFolder,
ext: [
'.js'
],
verbose:
}))
.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'
] }))
let wxssStream = gulp.src([srcFolder.wxssFile])
'.wxss'
// .pipe(changed(distFolder))
let jsonStream = gulp.src([srcFolder.jsonFile])
ext:
'.json'
let imagesStream = gulp.src(srcFolder.imagesFile)
'.png'
'.jpg'
'.gif'
.pipe(changed(distFolder))
.pipe(gulpif(!!options[
'zip-image'
], smushit({
})))
merge(jsStream, wxmlStream, wxssStream, jsonStream, imagesStream);
"watch"
(callback) {
watch(
'src/**/*'
, { debounceDelay: 200 },
(vinyl) {
gulp.start(
"doTask"
, callback);
"clean-reference"
gulp.src(
"src/nodemodules"
, { read:
'default'
runSequence(
'clean-reference'
'watch'
//gulp新建文件
'new-component'
let path = options.path;
(!path) {
callback(
'no paramter path'
let spitIndex = path.lastIndexOf(
'/'
let fileName = path.substring(spitIndex + 1);
'templates/component-master.tar.gz'
.pipe(decompress({ strip: 1 }))
.pipe(debug({ title:
'decompress:'
.pipe(rename(
(renamePath) {
(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}/`));
是否是有删除工具正在使用的 dist 目录呢?如果是的话,是有可能出现问题的,因为这个节点的删除工具有可能无法捕获到。建议工具直接在根目录建立项目,然后使用 project.config.json 指定 dist 目录为 miniprogramRoot,一样可以达到效果哦
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
1、工具是在 project.config.json 指定的 dist 目录,还是直接使用 dist 目录呢?
2、gulp 是否有 watch 呢,还是构建完毕即退出了
3、编辑设置里,是否有开启保存时自动编译等选项呢
直接使用了dist目录,未编辑过project.config.json
有加watch,watch延迟200ms
这个问题有可能跟我们文件多有关系吗?大概600-700个文件,我是固态硬盘
尝试去掉 “编译时自动保存所有文件” 试试呢
不起作用。有个现象很奇怪只有第一次执行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}/`));
})
是否是有删除工具正在使用的 dist 目录呢?如果是的话,是有可能出现问题的,因为这个节点的删除工具有可能无法捕获到。建议工具直接在根目录建立项目,然后使用 project.config.json 指定 dist 目录为 miniprogramRoot,一样可以达到效果哦