0

这是我的项目

 - Project root

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

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

 |-gulpfile.js

我使用 gulp 并希望将 build/scc 和 build/js 文件注入 src/index.html 并将其放置为 build/index.html

这样做:

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'));
});

我需要跳过 '/build/' 部分但仍然在 html 文件的输出中显示:

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

1 回答 1

0
- Project root

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

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

 |-gulpfile.js

现在我们在index.html哪个build目录(文件夹)中,我们需要后退一步才能访问该src目录,..并将成为当前目录的父目录(意味着build

那么你可以使用这个:

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

阅读有关相对路径和绝对路径的更多信息将帮助您了解有关此的更多信息

于 2016-12-19T10:10:39.020 回答