Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 吞咽和注入路径_Javascript_Node.js_Npm_Gulp_Gulp Inject - Fatal编程技术网

Javascript 吞咽和注入路径

Javascript 吞咽和注入路径,javascript,node.js,npm,gulp,gulp-inject,Javascript,Node.js,Npm,Gulp,Gulp Inject,在VisualStudio中,我有以下客户端项目结构 -wwwroot -app -js -views -css -images -lib index.html 使用gulp inject,我希望在index.html中插入javascript的路径: gulp.task('injecttest', function () { var target = gulp.src('wwwroot/index.html'); var

在VisualStudio中,我有以下客户端项目结构

-wwwroot
   -app
      -js
      -views
   -css
   -images
   -lib
   index.html
使用gulp inject,我希望在index.html中插入javascript的路径:

gulp.task('injecttest', function () {
    var target = gulp.src('wwwroot/index.html');
    var sources = gulp.src(['wwwroot/app/js/**/*.js'], { read: false });

    return target.pipe(inject(sources)).pipe(gulp.dest('wwwroot/'));;
});
gulpfile.js在wwwroot目录之外。 这里的问题是,在my index.html中,注入的格式为:

<script src="/wwwroot/app/js/RemoteCallServices.js"></script>

为了工作,我需要

<script src="app/js/RemoteCallServices.js"></script>


如何实现这一点?

您可以使用“大口注射”选项


这对我来说很有效,但是如果
src=“app/js/etc…”
我得到
src=“/app/js/etc…”
。知道如何删除额外的前导
/
?从ignorePath属性中删除额外的前导
/
。使用上面的示例,
{ignorePath:'wwwwroot/'}
Update:in,我看到我可以使用
addRootSlash:false
以及
ignorePath:'/wwwroot/'
。帮我修好了。
gulp.task('injecttest', function () {
    var target = gulp.src('wwwroot/index.html');
    var sources = gulp.src(['wwwroot/app/js/**/*.js'], { read: false });

    return target.pipe(inject(sources, { ignorePath: '/wwwrooot/')).pipe(gulp.dest('wwwroot/'));;
});