我有3个'cdn'文件。
EG。
http://www.cdn.com/js/script1.js (size: 10KB)
http://www.cdn.com/js/script2.js (size: 2KB)
http://www.cdn.com/js/script3.js (size: 15KB)
我需要下载以上3个文件& concat到'script.js'。 通过运行gulp命令,我创建了'script.js'。 但是'script.js'中缺少第一个文件(script1.js)。还有其他两个文件。
我改变了订单 即。
download(
[
"http://www.cdn.com/js/script2.js",(size: 2KB)
"http://www.cdn.com/js/script3.js",(size: 15KB)
"http://www.cdn.com/js/script1.js",(size: 10KB)
])
这次缺少script3.js,但是script1.js就在那里。
我的'gulp.js'文件
var gulp = require('gulp');
var del = require('del');
var download = require("gulp-download-stream");
var concat = require('gulp-concat');
var FileSystem = require('fs');
var PackageJSON = JSON.parse(FileSystem.readFileSync('package.json'));
var Destination = "cdn/"+PackageJSON.version;
gulp.task('clean', function()
{
return del([Destination]);
});
gulp.task('js', function()
{
download(
[
"http://www.cdn.com/js/script1.js",
"http://www.cdn.com/js/script2.js",
"http://www.cdn.com/js/script3.js",
])
.pipe(gulp.dest("temp/"));
return gulp.src("temp/*.js")
.pipe(concat('script.js'))
.pipe(gulp.dest(Destination+"/"));
});
gulp.task('default', ['clean','js']);
'的package.json'
{
"name": "",
"version": "4.0.0",
"description": "",
"main": "",
"dependencies":
{
"gulp": "^3.9.1"
},
"devDependencies":
{
"del": "^3.0.0",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-download-stream":"^0.0.1"
},
"scripts":
{
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
提前致谢
答案 0 :(得分:0)
您最初可能已经拥有此功能,但请在数组中查看尾随逗号:
download(
[
"http://www.cdn.com/js/script1.js",
"http://www.cdn.com/js/script2.js",
"http://www.cdn.com/js/script3.js"
])
我删除了最后一个逗号。也许这会破坏你的下载电话。