我正在运行一个gulp-concat
脚本,它将jquery、slick-carousel、t.js和我的index.js文件连接起来。
const pack = () => {
return gulp.src(['./node_modules/jquery/**/jquery.js', './node_modules/slick-carousel/**/slick.js', './assets/js/t.js-master/t.js', './js/index.js'])
// .pipe(gulp_babel({
// 'presets': ['@babel/env'],
// 'plugins': ["transform-remove-strict-mode"]
// }))
.pipe(gulp_concat('main.js'))
// .pipe(gulp_uglify())
.pipe(gulp.dest('./build'));
}
正如您所看到的,我删除了所有可能导致问题的管道。唯一运行的任务是gulp-concat
。(index.js
都在ES 5中,我运行的是最新版本的firefox,不需要babel atm)然而,当我打开页面时,我得到了错误
Uncaught ReferenceError: define is not defined
查看main.js,我在jquery部分的末尾发现了一个define
对象--但只在连接文件中,而不是node_modules
中的jquery。我没有添加这个对象,而且据我所知,我也没有使用require.js
:
define( [
"./core",
"./selector",
"./traversing",
"./callbacks",
"./deferred",
"./deferred/exceptionHook",
"./core/ready",
"./data",
"./queue",
"./queue/delay",
"./attributes",
"./event",
"./event/focusin",
"./manipulation",
"./manipulation/_evalUrl",
"./wrap",
"./css",
"./css/hiddenVisibleSelectors",
"./serialize",
"./ajax",
"./ajax/xhr",
"./ajax/script",
"./ajax/jsonp",
"./ajax/load",
"./core/parseXML",
"./core/parseHTML",
"./effects",
"./effects/animatedSelector",
"./offset",
"./dimensions",
"./deprecated",
"./exports/amd",
"./exports/global"
], function( jQuery ) {
"use strict";
return jQuery;
} ); // jQuery seems to end here
如何添加这些额外的代码,如何避免?我也在使用browserSync,但不认为这是相关的。
1条答案
按热度按时间x7rlezfr1#
我刚刚检查了jQuery的源代码,其中有一个文件:
https://github.com/jquery/jquery/blob/3.5.1/src/jquery.js
因此,您需要做的是简单地排除它,它应该修复这个问题:)