Questions tagged [gulp-inject]

Gulp-inject is a javascript, stylesheet and webcomponent injection plugin for Gulp streaming build system.

gulp-inject takes a stream of source files, transforms each file to a string and injects each transformed string into placeholders in the target stream files. See Basic usage and More examples below.

Default transforms and placeholders exists for injecting files into html, jade, jsx , less, slm, haml and sass / scss files.

https://www.npmjs.com/package/gulp-inject

npm install --save-dev gulp-inject

Basic usage

The target file src/index.html:

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
  <!-- inject:css -->
  <!-- endinject -->
</head>
<body>

  <!-- inject:js -->
  <!-- endinject -->
</body>
</html>

The gulpfile.js:

var gulp = require('gulp');
var inject = require('gulp-inject');

gulp.task('index', function () {
  var target = gulp.src('./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(['./src/**/*.js', './src/**/*.css'], {read: false});

  return target.pipe(inject(sources))
    .pipe(gulp.dest('./src'));
});
108 questions
12
votes
2 answers

Gulp-Inject Not Working

I have a simple Gulp build process setup for testing. I've read the documentation many times but I can't seem to get Gulp-inject to inject the scripts I want into an index.html file. My Gulp file looks like this: gulp.task('inject1', function() { …
Mike Fisher
  • 913
  • 3
  • 13
  • 27
10
votes
1 answer

How to copy and inject the main-bower-files in one step using gulp?

When deploying my app I want to copy the bower dependency to the deploy directory and inject the links to these files into the index.html that is also in the deploy directory. Each step alone works perfectly by I'm not able to combine them. Copy the…
Heiner
  • 1,869
  • 1
  • 19
  • 33
9
votes
2 answers

Gulp-inject transform doesn't work

I've tried to setup gulp-inject to inject dependencies into index.html. Everything works fine except transform function. I need to replace part of filepath in the following way: /frontend/src/ --> /static/ I've tried to do it like this (copy-pasted…
svfat
  • 3,273
  • 1
  • 15
  • 34
8
votes
2 answers

What gulp-angular-filesort really does for gulp-inject?

Can anybody show an example of what gulp-angular-filesort really does and how to use it properly? The thing is that I’ve recently realized that my gulp-angular-filesort doesn’t sort angularjs files at all, however my AngularJS App with lots of files…
zhekaus
  • 3,126
  • 6
  • 23
  • 46
7
votes
2 answers

How to combine gulp-watch and gulp-inject?

I am trying to use both gulp-watch and gulp-inject to build my Node Web app. However, it seems that the build step involving gulp-inject won't work once gulp-watch gets involved. Seemingly, the reason is that the watch stream never ends and…
aknuds1
  • 65,625
  • 67
  • 195
  • 317
6
votes
1 answer

Gulp-inject says "Nothing to inject into index.html"

I'm trying to inject some files in my index, all of them concatenated and minified into a .tmp folder, as follows: gulp.task('prep-js',['clean'], function(){ var jspath = './src/page/**/*.js'; var treatJs = gulp.src(jspath) …
6
votes
0 answers

gulp-inject says it injected files but target file remains the same

I am trying to inject all js files in the weebroot folder (except the ones in lib), and after running the task it says all the files were injected. Nothing really appears to be happening though. This is my task: gulp.task('index', function () { …
Julie Røsok
  • 109
  • 1
  • 4
6
votes
1 answer

Gulp cannot inject css and js at the same time

I am trying to run the following code var $ = require('gulp-load-plugins')({ lazy: true }); // fetches gulp plugins gulp.task('wiredep', function () { var wiredep = require('wiredep').stream; return gulp .src(config.index) …
eugenekgn
  • 1,652
  • 2
  • 17
  • 38
5
votes
1 answer

How to inject bower dependency in right order to jhipster project

I am trying to inject ngmap to my jhipster project. After installation dependency with bower install ngmap --save it appears in my bower.json file : { "version": "0.0.0", "name": "myApp", "appPath": "src/main/webapp/", "testPath":…
5
votes
1 answer

Troubleshooting slow gulp-inject

For some reason, gulp-inject recently started taking a long time (3 minutes). Previously it would take a few seconds. I'm not sure where to begin when diagnosing this issue. Here's my output: [18:04:39] gulp-inject 1 files into…
Will I AM
  • 220
  • 1
  • 9
5
votes
2 answers

Using gulp-inject: How to add query string to injected filename

I use gulp-inject to add files to load to index.html. To force browser to reload js-scripts, I want to add a query string to the filename that is injected into index.html. I suspect this is possible with gulp-inject's transform function. But reading…
EricC
  • 5,720
  • 13
  • 52
  • 71
5
votes
1 answer

How to add specific bower components as IE8 conditional block in Gulp

I have several bower components, of which I need some components like json3, respondjs, es5shim to be added in an IE8 conditional block (in build as well as serve) like this :