我有一个包含空传播运算符的JS表达式,但是当应用gulp作业缩小JS时,它失败了。有谁知道如何保持这个语法(不执行if/else或使用三元运算符(表达式)?真的:假的)?
我的表情
let tableTitle = $(config.$table[0])?.siblings('.title-section')[0]?.innerText;吞咽错误:
TypeError in plugin "gulp-minify"
Message: dev\js\app_delivery.js
Cannot read property 'replace' of undefined (line: undefined, col: undefined, pos: undefined
Details:
domainEmitter: [object Object]
domain: [object Object]
domainThrown: false我的吞咽任务导致错误:
gulp.task('JS-libs', function() {
return gulp.src(config.modules.JS.libs)
.pipe(concat('libs.js'))
.pipe(minifyJS())
.pipe(gulp.dest(config.path.dest.rootJS))
});minifyJS函数:
function minifyJS() {
return gulpMinifyJS({
ext:{
src: '.js',
min:'.min.js'
}
});
}以及我关于gulp的package.json配置:
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-concat": "^2.6.1",
"gulp-cssmin": "^0.2.0",
"gulp-minify": "^3.1.0",
"gulp-remove-logging": "^1.2.0",
"gulp-rename": "^1.4.0",
"gulp-replace": "^1.0.0",
"uglifyjs": "^2.4.11"提前感谢您的帮助
发布于 2020-10-08 15:18:31
我找到了一个解决办法,它的好处是在gulp上没有错误,并且在没有找到搜索到的HTML dom元素时,有一个表达式不会崩溃:
try {
let tableTitle = $(config.$table[0]).siblings('.title-section')[0].firstChild.nodeValue;
...
}
catch(error) {
...
console.error(error);
}然而,如果有人知道如何回答我的第一个问题,我会非常感激。
https://stackoverflow.com/questions/64263735
复制相似问题