Skip to content

Instantly share code, notes, and snippets.

@LoyEgor
Last active March 18, 2021 07:25
Show Gist options
  • Save LoyEgor/bd8c51695e778d3a627e04973342236d to your computer and use it in GitHub Desktop.
Save LoyEgor/bd8c51695e778d3a627e04973342236d to your computer and use it in GitHub Desktop.
inject js as async (custom way)
//install
//npm i gulp-inject group-array@0.3.1
var inject = require('gulp-inject');
//inject libs js
gulp.task('inject:js', function() {
return gulp.src('./app/*.html')
.pipe(inject(gulp.src('./app/js/libs.min.js', { //inject more than one js in capturedbyanastasiia
read: false //just inject no read
}), {
relative: true, //if true inject:js/libs.min.js, if false inject:/app/js/libs.min.js
transform: filepath => `<script src="${filepath}" async></script>`
}))
.pipe(gulp.dest('./dist'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment