问题描述
我使用包 gulp-less
和 gulp-sourcemaps
。我的较少文件位于 Styles / main.less
下,但生成的源映射指向 source / main.less
(其中 source /
似乎是一个前缀)。如何解决这个问题,所以源图正确指向 source / Styles / main.less
?
我的大嘴任务很简单:
var gulp = require('gulp'),
less = require('gulp-更少'),
gulpif = require('gulp-if'),
sourcemaps = require('gulp-sourcemaps');
var paths = {
styles:[
'Styles / ** / *。less',
'!** / *。min.css'
],
wwwRoot:'wwwroot /'
}
var isLessFile = function(file){return /.less$/.test(file.path); }
gulp.task('styles',function(){
return gulp
.src(paths.styles)
.pipe(sourcemaps.init() )
.pipe(gulpif(isLessFile,less()))
.pipe(sourcemaps.write('。'))
.pipe(gulp.dest(paths.wwwRoot +'styles '));
});
sourcemaps.write(' ',{includeContent:false,sourceRoot:'../ Styles'})
应该适合你。默认情况下,你的源内容包含在你的源代码文件中, sourceRoot
可能是'/ source /',这意味着使用嵌入式源文件。 includeContent:false
会阻止将源代码嵌入到源代码文件中,您还必须将 sourceRoot
属性设置为相对路径将源图保存到源文件所在的位置。在我的例子中,它将为Styles文件夹查找一个文件夹,这将被添加到源地图 sources
数组中的所有路径前面。
I use the packages gulp-less
and gulp-sourcemaps
. My less file is located under Styles/main.less
, but the generated source map points to source/main.less
(where source/
seems to be a prefix). How to fix this, so the source map correctly points to source/Styles/main.less
?
My gulp task is rather simple:
var gulp = require('gulp'),
less = require('gulp-less'),
gulpif = require('gulp-if'),
sourcemaps = require('gulp-sourcemaps');
var paths = {
styles: [
'Styles/**/*.less',
'!**/*.min.css'
],
wwwRoot: 'wwwroot/'
}
var isLessFile = function(file) { return /.less$/.test(file.path); }
gulp.task('styles', function() {
return gulp
.src(paths.styles)
.pipe(sourcemaps.init())
.pipe(gulpif(isLessFile, less()))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.wwwRoot + 'styles'));
});
sourcemaps.write('.',{includeContent:false, sourceRoot:'../Styles'})
Should work for you. By default you are including the source content in your sourcemap file and sourceRoot
is probably '/source/' which means to use the embedded source files. includeContent:false
will prevent embedding sources into the sourcemap file, you also have to set sourceRoot
property to a relative path from where you save your sourcemap to where your source files are located. In my example it will look one folder up for Styles folder, this will be prefixed to all paths in your sourcemaps sources
array.
这篇关于源地图的路径是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!