0
我的gulp文件的一部分沒有做任何事情,我沒有得到任何錯誤,但所需的文件沒有顯示(或正在被修改)。沒有創建文件的Gulp
完整的gulpFile在下面;並且雖然gulp任務'vendor'做它應該做的事情(在'build'dir中創建文件)... gulp任務'js'和'build'不會在'build'中創建預期的'app.js' DIR。
由於「JS」和「構建」使用「事件流」和功能getTemplateStream(),我懷疑這個問題是存在的
確認;如果我刪除這些元素,這個工程:
gulp.task('x', function() {
gulp.src(source.js.src)
.pipe(concat('app.js'))
.pipe(gulp.dest('build'))
});
我似乎無法CONSOLE.LOG()或得到一個錯誤 - 讓我無所適從 任何幫助 - 非常感謝
/*
GULP BUILD SYSTEM
-Will watch and compress files, as needed, restart server on change in dev mode
-Will create a single "vendor.js" uglified file for any JS files specified in the "app.scripts.json" file
-will move condensed files to "build"
*/
var es = require('event-stream');
var gulp = require('gulp');
var concat = require('gulp-concat');
var connect = require('gulp-connect');
var templateCache = require('gulp-angular-templatecache');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var fs = require('fs');
var _ = require('lodash');
var scripts = require('./app.scripts.json'); // for vendor.js
var source = {
js: {
main: 'app/main.js',
src: [ 'app.config.js',
'app/main.js',
'app/app.js',
'app/**/module.js',
'app/**/!(module)*.js' ],
tpl: 'app/**/*.tpl.html'
}
};
var destinations = {
js: 'build'
};
// FUNCTIONS
var swallowError = function(error) {
console.error.bind(error.toString());
this.emit('end');
};
var getTemplateStream = function() {
return
gulp.src(source.js.tpl)
.pipe(templateCache({
root: 'app/',
module: 'app'
}))
};
// GULP TASKS
gulp.task('build', function() {
return
es.merge(gulp.src(source.js.src) , getTemplateStream())
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(concat('app.js'))
.on('error', swallowError)
.pipe(gulp.dest(destinations.js));
});
gulp.task('js', function() {
return
es.merge(gulp.src(source.js.src) , getTemplateStream())
.pipe(concat('app.js'))
.on('error', swallowError)
.pipe(gulp.dest(destinations.js));
});
gulp.task('vendor', function() {
_.forIn(scripts.chunks, function(chunkScripts, chunkName) {
var paths = [];
chunkScripts.forEach(function(script) {
var scriptFileName = scripts.paths[script];
if (!fs.existsSync(__dirname + '/' + scriptFileName)) {
throw console.error('Required path doesn\'t exist: ' + __dirname + '/' + scriptFileName, script);
}
paths.push(scriptFileName);
//console.log('vendor file ' + scriptFileName + ' added to vendor.js.');
});
gulp.src(paths)
.pipe(concat(chunkName + '.js'))
.on('error', swallowError)
.pipe(gulp.dest(destinations.js))
});
});
gulp.task('watch', function() {
gulp.watch(source.js.src, ['js']);
gulp.watch(source.js.tpl, ['js']);
});
gulp.task('connect', function() {
connect.server({
port: 8888
});
});
gulp.task('prod', ['vendor', 'build']);
gulp.task('dev', ['vendor', 'js', 'watch', 'connect']);
gulp.task('default', ['dev']);
// END GULP TASKS
可能的重複[什麼是JavaScript的自動分號插入(ASI)的規則?](http://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-插入-ASI) –