Skip to content

Instantly share code, notes, and snippets.

@LoicGoyet
Last active January 14, 2016 16:57
Show Gist options
  • Save LoicGoyet/89c4fd5318d0f0db0dec to your computer and use it in GitHub Desktop.
Save LoicGoyet/89c4fd5318d0f0db0dec to your computer and use it in GitHub Desktop.
Basic usage of gulp-inject plugin
var gulp = require('gulp');
var inject = require('gulp-inject');
gulp.task('inject', function () {
var target = gulp.src('index.html');
// It's not necessary to read the files (will speed up things), we're only after their paths:
var sources = gulp.src(['style.css', 'script.js'], {read: false});
return target.pipe(inject(sources))
.pipe(gulp.dest('result.html'));
});
<!DOCTYPE html>
<html>
<head>
<title>My index</title>
<!-- inject:css -->
<!-- endinject -->
</head>
<body>
<!-- inject:js -->
<!-- endinject -->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>My index</title>
<!-- inject:css -->
<link rel="stylesheet" href="/style.css">
<!-- endinject -->
</head>
<body>
<!-- inject:js -->
<script src="/script.js"></script>
<!-- endinject -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment