我正在为一个非常烦人的错误而苦苦挣扎。首先:我是 gulp 的新手。
我尝试使用 Angular 实现单页应用程序。为了让我的工作流程更好,我尝试实现 gulp。
我在安装一些 gulp 插件时遇到了一些严重的 npm 错误,但这是另一个故事,我意识到它在有或没有错误的情况下工作。
我真正想到的是 useref 插件。或者更准确地说,uglify 插件。
这是在我的 gulpfile.js 中:
gulp.task('useref', function() {
return gulp.src('app/*.html')
.pipe(useref())
.pipe(gulpIf('*.js', uglify()))
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dist'))
});
这是它在尝试运行它时抛出的堆栈跟踪。C:\Work\evori-portfolio>gulp useref
[16:32:40] Using gulpfile C:\Work\evori-portfolio\gulpfile.js
[16:32:40] Starting 'useref'...
events.js:141
throw er; // Unhandled 'error' event
^
Error
at new JS_Parse_Error (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:1526:18)
at js_error (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:1534:11)
at croak (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2025:9)
at token_error (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2033:9)
at expect_token (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2046:9)
at expect (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2049:36)
at eval (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2602:13)
at eval (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2072:24)
at expr_atom (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2532:35)
at maybe_unary (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2708:19)
这个堆栈跟踪对我来说绝对没有任何意义。
我查看了堆栈跟踪中列出的所有目的地,没有发现任何故障。
我认为这可能是由 gulp 所做的异步工作引起的。可能是 uglify 插件试图对此时未完成的 useref 文件进行 uglify。怎么知道?
因此,我将所有内容分开以确保错误不是由重叠插件引起的。
这就是我重现错误的方式: 1. gulp clean:dist
gulp.task('clean:dist', function() {
return del.sync('dist')
});
一饮而尽
gulp.task('useref', function() { return gulp.src('app/*.html') .pipe(useref()) .pipe(gulp.dest('dist')) });
吞咽缩小
gulp.task('minify', function() { return gulp.src('dist/**/*.js') /*.pipe(gulpIf('*.css', cssnano()))*/ .pipe(uglify()) .pipe(gulp.dest('dist')) });
对堆栈跟踪感到疯狂
C:\Work\evori-portfolio>gulp minify [11:55:50] Using gulpfile C:\Work\evori-portfolio\gulpfile.js [11:55:50] Starting 'minify'...
events.js:141 throw er; // Unhandled 'error' event ^ Error at new JS_Parse_Error (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:1526:18) at js_error (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:1534:11) at croak (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2025:9) at token_error (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2033:9) at expect_token (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2046:9) at expect (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2049:36) at eval (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2602:13) at eval (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2072:24) at expr_atom (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2532:35) at maybe_unary (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2708:19) at expr_ops (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2743:24) at maybe_conditional (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2748:20) at maybe_assign (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2772:20) at expression (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2791:20) at eval (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2173:39) at eval (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2072:24) at block_ (eval at <anonymous> (C:\Work\evori-portfolio\node_modules\uglify-js\tools\node.js:22:1), <anonymous>:2352:20)
编辑好的...我的 index.html 文件中有大量 .js 文件。我试图获取该文件,这会通过删除每个文件并尝试运行 useref+minify 来导致错误。我明白了。坏文件。当它从 index.html 中删除时,缩小就像一个魅力。但我不知道,我做错了什么或可能导致错误。
'use strict';
angular.module('previewApp')
.factory('dienstleisterRegObjService', function() {
/* Aktuell ausgewähltes Produkt */
var vorselektiertesProdukt = {
servicetyp: '',
dienstleistungstyp: '',
produkt: ''
};
/* Registrations Objekt; wird per API an Server übergeben */
var regObj = {
organisation: '',
vorname: '',
nachname: '',
mail: '',
nationalitaet: 'Schweiz',
sprache: 'Deutsch',
produkte: []
};
/* Reset Methods */
var getNewVorSelektProd = function() {
vorselektiertesProdukt.servicetyp = '';
vorselektiertesProdukt.dienstleistungstyp = '';
vorselektiertesProdukt.produkt = '';
};
var getNewRegObj = function() {
regObj.organisation = '';
regObj.vorname = '';
regObj.nachname = '';
regObj.mail = '';
regObj.nationalitaet = 'Schweiz';
regObj.sprache = 'Deutsch';
regObj.produkte = [];
};
/* Service Objekt */
return {
vorselektiertesProdukt,
regObj,
addProduct: function(servicetyp, dienstleistungstyp, produktparam) {
var produkt = {};
produkt.servicetyp = servicetyp;
produkt.dienstleistungstyp = dienstleistungstyp;
produkt.produkt = produktparam;
regObj.produkte.push(produkt);
},
deleteProduct: function(produkt) {
var index = regObj.produkte.indexOf(produkt);
regObj.produkte.splice(index, 1);
},
resetVorSelektProd: function() {
getNewVorSelektProd();
},
resetRegObj: function() {
getNewRegObj();
},
resetAllObj: function() {
getNewVorSelektProd();
getNewRegObj();
}
};
});