Created
November 5, 2015 22:17
-
-
Save troutacular/988bf3a917b263541ac4 to your computer and use it in GitHub Desktop.
Gulp Inject - Single and Multiple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gulp.task('scripts_insert', ['vendor_scripts', 'site_scripts'], function () { | |
var transform = function(filepath, file, i, length) { | |
return '<script src="' + filepath + '" async></script>'; | |
}; | |
return gulp.src(paths.js.template) | |
.pipe(inject(gulp.src(paths.js.dest.lib + '/*.js', {read: false}), {addRootSlash: false, transform: transform})) | |
.pipe(gulp.dest(base_paths.templates)); | |
}); | |
/* used only if multiple scripts are necessary */ | |
gulp.task('multiple_scripts_insert', ['vendor_scripts', 'site_scripts'], function () { | |
var vendor_stream = gulp.src([paths.js.dest.vendor + '/*.js'], {read: false}); | |
var lib_stream = gulp.src([paths.js.dest.lib + '/*.js'], {read: false, transform: transform}); | |
return gulp.src(paths.js.template) | |
.pipe(inject(series(vendor_stream, lib_stream),{addRootSlash: false})) // This will always inject vendor files before app files | |
.pipe(gulp.dest(base_paths.templates)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment