Visual studio 2015 尝试缩小js文件时,gulp进程终止,代码为0
我是一个刚开始吞咽的人,我犯了一个主题中描述的错误 进程已终止,代码为0 以下是npm创建的目录结构 来自我的package.json文件,该文件基于《英雄之角之旅》教程和网络上的一些其他参考资料Visual studio 2015 尝试缩小js文件时,gulp进程终止,代码为0,visual-studio-2015,npm,gulp,Visual Studio 2015,Npm,Gulp,我是一个刚开始吞咽的人,我犯了一个主题中描述的错误 进程已终止,代码为0 以下是npm创建的目录结构 来自我的package.json文件,该文件基于《英雄之角之旅》教程和网络上的一些其他参考资料 { "version": "1.0.0", "name": "myapp", "private": true, "dependencies": { "@angular/common": "2.0.0-rc.5", "@angular/compile
{
"version": "1.0.0",
"name": "myapp",
"private": true,
"dependencies": {
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/core": "2.0.0-rc.5",
"@angular/forms": "0.3.0",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.5",
"systemjs": "0.19.27",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"angular2-in-memory-web-api": "0.0.15",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"typescript": "^1.8.10",
"gulp": "^3.9.1",
"path": "^0.12.7",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0",
"gulp-typescript": "^2.13.6",
"typings": "^1.3.1",
"gulp-tsc": "^1.2.0",
"gulp-cssmin": "0.1.7",
"gulp-uglify": "1.2.0",
"gulp-rename": "1.2.2",
"rimraf": "2.2.8",
"concurrently": "^1.0.0",
"lite-server": "^1.3.1",
"lodash": "3.10.1"
},
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
}
}
这是我的吞咽脚本
var ts = require('gulp-typescript');
var gulp = require('gulp');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
//take all angular related files
var npmSources = [
'node_modules/@angular/**/bundles/*.umd.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/rxjs/bundles/Rx.js'
];
var bowerSources = './wwwroot/lib/hammer.js/hammer.js';
var destPath = './wwwroot/lib/min';
// Delete the dist directory
gulp.task('clean', function () {
return gulp.src(destPath)
.pipe(clean());
});
// Concatenate & Minify JS
gulp.task('minify-js', function() {
return gulp.src([npmSources,"!" + bowerSources])
.pipe(concat('libs.js'))
.pipe(gulp.dest(destPath))
.pipe(rename('libs.min.js'))
.pipe(uglify())
.pipe(gulp.dest(destPath));
});
gulp.task('default', ['clean','minify-js']);
在上面的npmSources
中,我试图包含所有angular 2相关的库文件,而不必使用这个->'node_modules/@angular/**/bundles/*.umd.js',
我上面收到的错误消息没有给我任何关于哪里出了问题以及哪里出了问题的线索。我的吞咽脚本有什么错误吗?我的目的是将所有angular 2相关脚本复制到目标路径,缩小为一个文件,而不必键入每个库。稍后我想对css文件做同样的处理
这就是我的node\u modules
文件夹在package.json文件保存到VS2015后的样子
正如您所看到的,这里的文件夹比我在package.json
文件中列出的文件夹多得多。我假设这些是必需的依赖项,不需要在gulpvar npmSources=[…]
我正在使用Visual Studio 2015并使用其任务运行程序运行gulp任务。我使用bower也是因为hammer.js在npm注册表中不可用
编辑:运行gulp文件时的错误代码
[23:06:46] Using gulpfile C:\UI\Gulpfile.js
[23:06:46] Starting 'clean'...
[23:06:46] Starting 'minify-js'...
[23:06:46] 'minify-js' errored after 1.15 ms
[23:06:46] Error: Missing positive glob
at Object.gs.create (C:\UI\node_modules\glob-stream\index.js:73:39)
at Gulp.src (C:\UI\node_modules\vinyl-fs\lib\src\index.js:33:23)
at Gulp.<anonymous> (C:\UI\Gulpfile.js:38:17)
at module.exports (C:\UI\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\UI\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (C:\UI\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (C:\UI\node_modules\orchestrator\index.js:134:8)
at C:\UI\node_modules\gulp\bin\gulp.js:129:20
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
[23:06:47] Finished 'clean' after 40 ms
Process terminated with code 1.
[23:06:46]使用gulpfile C:\UI\gulpfile.js
[23:06:46]开始“清理”。。。
[23:06:46]正在启动“缩小js”。。。
[23:06:46]“缩小js”在1.15毫秒后出错
[23:06:46]错误:缺少正全局变量
在Object.gs.create(C:\UI\node\u modules\glob stream\index.js:73:39)
在Gulp.src(C:\UI\node\u modules\乙烯基fs\lib\src\index.js:33:23)
狼吞虎咽。(C:\UI\Gulpfile.js:38:17)
在module.exports(C:\UI\node\u modules\orchestrator\lib\runTask.js:34:7)
在Gulp.Orchestrator.\u runTask(C:\UI\node\u modules\Orchestrator\index.js:273:3)
在Gulp.Orchestrator.\u runStep(C:\UI\node\u modules\Orchestrator\index.js:214:10)
在Gulp.Orchestrator.start(C:\UI\node\u modules\Orchestrator\index.js:134:8)
在C:\UI\node\u modules\gulp\bin\gulp.js:129:20
在下一个TTickCallbackwith0args(node.js:420:9)
在进程中调用(node.js:349:13)
[23:06:47]40毫秒后完成“清洁”
进程以代码1终止。
正如你在评论中所发现的那样[edit:hmm…我是想象过那条评论还是你删除了它?[edit:aha它回来了!哈哈]],麻烦在于将数组npmSources
带入minify js
任务的gulp.src
glob:
…
var npmSources = [
'node_modules/@angular/**/bundles/*.umd.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/rxjs/bundles/Rx.js'
];
var bowerSources = './wwwroot/lib/hammer.js/hammer.js';
var destPath = './wwwroot/lib/min';
…
// Concatenate & Minify JS
gulp.task('minify-js', function() {
return gulp.src([npmSources,"!" + bowerSources])
.pipe(concat('libs.js'))
.pipe(gulp.dest(destPath))
.pipe(rename('libs.min.js'))
.pipe(uglify())
.pipe(gulp.dest(destPath));
});
…
那是因为(A)
你是说(B)
当你需要说(C)
(事实上,我不确定当数组被替换为变量时,数组在A中的表示方式是否正确。但是,例如,即使它没有被读取,结果也是等效的:在A和B中,gulp都会抛出相同的“错误:缺少正glob”。)
因为在您提供的内容中,没有理由为源文件使用单独的变量,所以您可以保存几个字节,并直接在gulp.src
中提供它。这也是学习吞咽的好地方:
…
var destPath = './wwwroot/lib/min';
…
// Concatenate & Minify JS
gulp.task('minify-js', function() {
return gulp.src([
'node_modules/@angular/**/bundles/*.umd.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/rxjs/bundles/Rx.js',
'!./wwwroot/lib/hammer.js/hammer.js'
])
.pipe(concat('libs.js'))
.pipe(gulp.dest(destPath))
.pipe(rename('libs.min.js'))
.pipe(uglify())
.pipe(gulp.dest(destPath));
});
…
还请注意,/wwwroot/lib/hammer.js/hammer.js似乎没有必要:您正在从glob中删除它,但一开始它并不匹配。(该gulp.src
行表示,“Getnode_modules/@angular/**/bundles/*.umd.js
,
node\u modules/systemjs/dist/system.src.js
,和node\u modules/rxjs/bundles/Rx.js
,然后排除/wwwwroot/lib/hammer.js/hammer.js
)你试过削减gulpfile吗?e、 g.如果gulp.task('default',function(){console.log(“无代码0 plz”)}),会发生什么情况
,然后保持您的默认值
不变,并将清理
和缩小js
更改为只记录消息,这将提供此>>>[22:47:20]启动“默认值”。。。182μs进程以代码0终止后,没有代码0 plz[22:47:20]完成“默认”。很好,所以我们知道gulp正在工作。听起来你还没试过调试这个?接下来,我会尝试gulp clean
,看看这是否有效,然后gulp minify js
,看看这是否适用于clean和minify js我得到这个>>>[22:48:48]开始“clean”。。。[22:48:48]正在启动“缩小js”。。。[22:49:02]在15秒后完成“清理”[22:49:05]在18秒后完成“缩小js”[22:49:05]开始“默认”。。。[22:49:05]在33μs进程以代码0终止后,完成了“默认设置”。
clean似乎正在清理文件夹
gulp.task('myTask', function() {
gulp.src([['1','2']]);
});
gulp.task('myTask', function() {
gulp.src(['1','2']);
});
…
var destPath = './wwwroot/lib/min';
…
// Concatenate & Minify JS
gulp.task('minify-js', function() {
return gulp.src([
'node_modules/@angular/**/bundles/*.umd.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/rxjs/bundles/Rx.js',
'!./wwwroot/lib/hammer.js/hammer.js'
])
.pipe(concat('libs.js'))
.pipe(gulp.dest(destPath))
.pipe(rename('libs.min.js'))
.pipe(uglify())
.pipe(gulp.dest(destPath));
});
…