setting the right directory on css inject

42 views Asked by At

this is my project

 - Project root

 |-  build
     |-css
     |-js
     |-index.html

 |-  src
     |- css
     |- js
     |-index.html

 |-gulpfile.js

I use gulp and want to inject build/scc and build/js files into src/index.html and place it as build/index.html

Done this :

gulp.task('index', function () {
  var target = gulp.src('src/index.html');
  var sources = gulp.src(['build/js/*.js', 'build/styles/*.css'], { ignorePath: 'build/', addRootSlash: false });
  return target.pipe(inject(sources))
    .pipe(gulp.dest('build'));
});

I need to skip the '/build/' part But still on output of html file shows :

<link rel="stylesheet" href="/build/styles/app.min.css">
<script src="/build/js/app.min.js"></script>
1

There are 1 answers

0
Mohammad Kermani On
- Project root

 |-  build
     |-css
     |-js
     |-index.html

 |-  src
     |- css
     |- js
     |-index.html

 |-gulpfile.js

Now we are in index.html which is in build directory(folder), we need to go a step backward to have access to the src directory, and .. will be the parent directory of the current directory (means build)

then you can use this:

<link rel="stylesheet" href="../build/styles/app.min.css">

Reading more about relative and absolute path will help you to learn more about this