Not able to correctly inject files using gulp

42 views Asked by At

My app structure is following:

-gulp
-src
 -app
 -assets
  -css

I want to insert files from "css" folder in index.html which is in "src" folder.

1

There are 1 answers

0
Dilakshan Sooriyanathan On

use the below code and set the path accurately.

var inject = require('gulp-inject');
var $ = require('gulp-load-plugins')({ lazy: true });



gulp.task('inject', function () {

        var injectStyles = gulp.src(['css/*.css'], { read: false } );

        return gulp.src( '/src/index.html')
            .pipe($.inject(injectStyles, { relative: true }))
            .pipe(gulp.dest('/src'));
    });

specially you need to enter styles comment tag in your html file as below:

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

  <!-- inject:css -->
  <!-- endinject -->

</head>