我在使用这个有用的工具时遇到了麻烦,我不知道该怎么办,这就是为什么我来这里向你寻求帮助的原因。
这是我的目录结构:
- Project root
|- dist
|-css
|-js
|- source
|- css
|- js
|-index.html
|-gulpfile.js
|-index.html 因此,我使用gulp将源文件夹中的css、js注入dist文件夹,缩小、连接等。然后,将其注入源文件夹中的index.html中,并将其吐到项目根文件夹中。代码如下:
//Injects assets (css,js) into index.html automatically
gulp.task('inject',['sass','concat-css','concat-js'],function(){
//Target to inject
var target = gulp.src('source/index.html');
//Sources to be injected
var cssFiles = gulp.src('./dist/assets/css/*.css',{read:false});
var jsFiles = gulp.src('./dist/assets/js/*.js',{read:false});
//Merge resources into one
var sources = es.merge(cssFiles,jsFiles);
//Injecting bower.json dependencies and other resources
return target.pipe(inject(sources),{
ignorePath:'dist/',
addRootSlash:false
})
.pipe(wiredep({ignorePath:'../'}))
.pipe(gulp.dest('./'));
});问题是index.html上dist文件夹的路径如下所示:
"/dist/css/stylesheet.css"导致错误,因为它应该是:`"dist/css/stylesheet.css“
正如您在代码中看到的,我使用了注入器的选项ignorePath、addRootSlash、relative:true,但似乎什么都不起作用。同样的事情也发生在wiredep上,但是这个是接受ignorePath选项,所以一切都很好。
提前感谢您的帮助。
发布于 2015-09-25 00:39:25
看起来您错误地将inject选项作为pipe函数的第二个参数。尝试:
target.pipe(inject(sources, { ignorePath: 'dist/', addRootSlash: false }))发布于 2015-12-04 22:43:48
您应该在inject中设置relative选项,如下所示:
inject(sources, { relative: true })发布于 2016-03-08 21:20:19
您可以使用两个选项来插入:ignorePath和addRootSlash
var injectOptions = {
addRootSlash: false,
ignorePath: 'dist/'
};
target.pipe(inject(sources),injectOptions)https://stackoverflow.com/questions/32550713
复制相似问题