[英]Gulp minified js throws error
We have lots of separate JavaScript files, and of course they are minified into various others in Production. 我们有很多单独的JavaScript文件,当然它们在生产中被缩小为其他各种文件。 Currently we use Microsoft Ajax Minifier from command line for this task, but the intention is to switch to gulpjs .
目前我们从命令行使用Microsoft Ajax Minifier来完成此任务,但目的是切换到gulpjs 。
The minification process itself seems to be okay, all the output files are generated, no error is written to output, etc. 缩小过程本身似乎没问题,生成所有输出文件,没有错误写入输出等。
But I have a weird issue, ~4-5 out of 16 minified files generated by gulpjs
throw various errors, such as: 但我有一个奇怪的问题,
gulpjs
生成的16个缩小文件中有4-5个抛出各种错误,例如:
Cannot read property '...' of undefined
无法读取未定义的属性'...'
or 要么
Uncaught TypeError: (intermediate value)(intermediate value)(...) is not a function
未捕获的TypeError :(中间值)(中间值)(...)不是函数
Ajax minifier is called as follows: Ajax minifier的调用方式如下:
AjaxMin.exe -js -xml .\minify.xml -clobber -evals:safeall
A sample from the minify.xml
: minify.xml
的示例:
<?xml version="1.0" encoding="utf-8"?>
<root>
<output path="..\js\min\main.min.js">
<input path="..\js\filename1.js"/>
<input path="..\js\filename2.js"/>
<input path="..\js\filename3.js"/>
...
</output>
<output path="..\js\min\report.min.js">
<input path="..\js\filename4.js"/>
<input path="..\js\filename5.js"/>
<input path="..\js\filename6.js"/>
...
</output>
...
</root>
A sample from gulpfile.js
来自
gulpfile.js
的示例
gulp.task("[js]minify-all", function () {
var mainFiles = [
"./js/filename1.js",
"./js/filename2.js",
"./js/filename3.js",
];
var reportFiles = [
"./js/filename4.js",
"./js/filename5.js",
"./js/filename6.js",
];
...
generateMinifiedFile(mainFiles, "./js/min/", "main");
generateMinifiedFile(reportFiles, "./js/min/", "report");
...
}
var generateMinifiedFile = function(inputFiles, outputPath, outputFileName) {
gulp.src(inputFiles)
.pipe(concat(outputFileName + ".js"))
.pipe(minify({
ext: {
min: ".min.js"
},
noSource: true
}))
.pipe(gulp.dest(outputPath));
};
In case it matters, here's package.json
万一重要,这里是
package.json
{
"name": "package",
"version": "1.0.0",
"private": true,
"devDependencies": {
"gulp": "3.9.1",
"gulp-bower": "0.0.13",
"gulp-concat": "^2.6.0",
"gulp-config": "0.3.0",
"gulp-less": "3.0.5",
"gulp-minify": "0.0.12",
"gulp-minify-css": "1.2.4",
"gulp-plumber": "1.1.0",
"gulp-watch": "4.3.5"
}
}
To sum it up: 把它们加起来:
AjaxMin.exe
, the site works fine. AjaxMin.exe
创建的缩小的js文件,该网站工作正常。 gulpjs
, the site breaks. gulpjs
创建的缩小的js文件,该站点中断。 Anyone has a suggestion what I miss? 任何人都有我想念的建议吗?
UPDATE UPDATE
Sample of creating a controller: 创建控制器的示例:
var settingsModule = angular.module("settingsModule", ["rootModule"]);
settingsModule.controller('settingsCasesController', ["$rootScope", "$scope", "$http", "DataService", function ($rootScope, $scope, $http, dataService) {
...
}
Note: This should be a comment, but It is an answer since it's a bit long, and an answer is easyer to write and to read... 注意:这应该是一个评论,但这是一个答案,因为它有点长,答案是更容易写和阅读...
To start with, I'd try setting to false
both gulp-minify
options mangle
and compress
. 首先,我想尝试设置为
false
都gulp-minify
选择mangle
和compress
。
If code runs ok, you should try setting to false
only one option, to see which one is responsible of the failure. 如果代码运行正常,您应该尝试设置为
false
只有一个选项,以查看哪个选项导致失败。
If code breaks (this would be quite strange, since I suppose the main task of a minifier is to compress and to mangle...), I'd try to manually compare the output of one gulp-minify
ed file to the source, to see what are the changes... 如果代码中断(这会很奇怪,因为我认为minifier的主要任务是压缩和破坏......),我会尝试手动比较一个
gulp-minify
ed文件的输出到源,看看有什么变化......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.