Alaksandar Jesus Gene
Alaksandar Jesus Gene

Reputation: 6883

gulp inject pointing to destination folder

I am using coffee script to generate my js and i am ok with generating it to dist folder from src folder. now trying to autoload those files using gulp-inject and following is my code.

gulpfile.js

gulp.task('inject', function () {
  var target = gulp.src('./dist/index.html');
  // It's not necessary to read the files (will speed up things), we're only after their paths: 
  var sources = gulp.src(['./scripts/**/*.js','./partials/**/*.js', './styles/**/*.css'], {read: false},{relative: false});

  return target.pipe(plugins.inject(sources))
    .pipe(gulp.dest('./dist'));
});

The resultant output is coming in dist/index.html

<!--inject:js--><script src="/dist/scripts/app.js"></script><script src="/dist/scripts/config.js"></script><script src="/dist/scripts/routes.js"></script><script src="/dist/partials/home/home.controller.js"></script><!--endinject-->

I want it to be like scripts/routes.js and scripts/config.js

As i use browser-sync, its pointing to dist folder which is the root folder. I tried on combinations but nothing fitted out. Point me through the right code.

Upvotes: 2

Views: 901

Answers (1)

What-About-Bob
What-About-Bob

Reputation: 649

You put { relative: false } on gulp.src(). This option belongs in inject()

    var sources = gulp.src(['./scripts/**/*.js', './partials/**/*.js', './styles/**/*.css'], { read: false });

    return target.pipe(plugins.inject(sources, { relative: false }))
      .pipe(gulp.dest('./dist'));

If relative doesn't do what you need see Clarifying injected paths for other options.

Upvotes: 2

Related Questions