Skip to content

Instantly share code, notes, and snippets.

@troutacular
Created November 5, 2015 22:17
Show Gist options
  • Save troutacular/988bf3a917b263541ac4 to your computer and use it in GitHub Desktop.
Save troutacular/988bf3a917b263541ac4 to your computer and use it in GitHub Desktop.
Gulp Inject - Single and Multiple
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