Answer the question
In order to leave comments, you need to log in
How to implement file priority in Gulp or Grunt?
The essence of the problem is this: the project has a "vendor" folder in which all files with classes from the engine developers are collected, and there is a "views" folder in which some classes are overridden.
The task is that when building the project, the collector would check if there is a file with an overridden class, and load it, and if not, then take it from "vendor".
Answer the question
In order to leave comments, you need to log in
This problem was solved like this:
gulpfile.js
var gulp = require('gulp');
var resolveDependencies = require('gulp-resolve-dependencies');
var concat = require('gulp-concat');
var del = require('del');
var order = require('gulp-order');
// JS tasks
// ==========================
// merge files from 2 directories and put them to tmp folder
gulp.task('js:merge', function (cb) {
var stream = gulp
.src(['./base/js/**/**', './js/**/**'])
.pipe(gulp.dest('./merged-js'))
;
stream.on('end', function () {
cb();
});
});
// resolve dependencies and build concatenated version
gulp.task('js:concat', ['js:merge'], function (cb) {
var stream = gulp
.src(['./merged-js/**/**'])
.pipe(order([
'constants.js',
'config-base.js',
'config.js',
'app.js',
'utils/*',
'services/*',
'controllers/**/**',
'ui/*',
'views/**/**',
'bootstrap.js'
]))
.pipe(resolveDependencies({
resolvePath: function (match, targetFile) {
return './merged-js/' + match;
}
}))
.pipe(concat('build.js'))
.pipe(gulp.dest('./'))
;
stream.on('end', function () {
cb();
});
});
// delete tmp folder
gulp.task('js:cleanup', ['js:concat'], function () {
del('./merged-js');
});
// ==========================
// HTML tasks
// ==========================
gulp.task('html:merge', function (cb) {
var stream = gulp
.src(['./base/views/**/**', './views/**/**'])
.pipe(gulp.dest('./merged-html'))
;
stream.on('end', function () {
cb();
});
});
gulp.task('html:concat', ['html:merge'], function (cb) {
var stream = gulp
.src(['./merged-html/**/**'])
.pipe(order([
'index.start.html',
'body.html',
'templates/**/**',
'index.end.html'
]))
.pipe(concat('index.html'))
.pipe(gulp.dest('./'))
;
stream.on('end', function () {
cb();
});
});
// delete tmp folder
gulp.task('html:cleanup', ['html:concat'], function () {
del('./merged-html');
});
// ==========================
// Default Task
gulp.task('default', [
'js:merge', 'js:concat', 'js:cleanup',
'html:merge', 'html:concat', 'html:cleanup'
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question