Javascript 吞咽和注入路径
在VisualStudio中,我有以下客户端项目结构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
-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/'));;
});