简体   繁体   English

使用Grunt减少SourceMap绝对文件路径

[英]Less SourceMap absolute file paths using Grunt

I have a file structure that looks like this (simplified for brevity): 我有一个看起来像这样的文件结构(为简便起见简化):

/less/
     /styles.less
/public/
       /css/
           /styles.css
           /styles.css.map
/gruntfile.js

Gruntfile.js: Gruntfile.js:

less: {
    options: {
        sourceMap: true,
        sourceMapFilename: 'public/css/styles.css.map',
        sourceMapURL: 'less/styles.less'
    }
    files: {
        'public/css/styles.css': 'less/styles.less'
    }
}

In the html file: <link rel="stylesheet" href="/css/styles.css"> 在html文件中: <link rel="stylesheet" href="/css/styles.css">

Now the issue is that in dev tools, styles.less points to /css/less/styles.less . 现在的问题是,在开发工具中, styles.less指向/css/less/styles.less That's clearly not right, as it should be /less/styles.less . 这显然是不对的,因为它应该是/less/styles.less But I can seem to get it to point to the project root. 但是我似乎可以使它指向项目根目录。

I've tried sourceMapBasepath and sourceMapRootpath options without any luck. 我已经尝试了sourceMapBasepathsourceMapRootpath选项,但没有任何运气。

Thoughts? 思考?

Another thing is in my css file ( /css/styles.css ), I get this: 另一件事是在我的css文件( /css/styles.css )中,我得到了:

/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjp... */

Why is it a base64 output? 为什么它是base64输出? I thought it should just point to the styles.css.map file. 我认为它应该只指向styles.css.map文件。

with grunt-contribe-less 1.0.0 使用grunt-contribe-less 1.0.0

the following task 以下任务

less: {
    options: {
      sourceMap: true,
      sourceMapRootpath: '/'

    },
    files: {'css/t.css' : 'less/t.less'}
  }

} }

generate a css/t.css , and a css/t.css.map . 生成一个css/t.css和一个css/t.css.map The last file will be generated automatically without need to set sourceMapFilename. 最后一个文件将自动生成,而无需设置sourceMapFilename。

The above does not generate a inline source map (with base64 output). 上面的代码不会生成内联源映射(带有base64输出)。

css/t.css ends with: css/t.css结尾于:

/*# sourceMappingURL=css/t.css.map */ / *#sourceMappingURL = css / t.css.map * /

Possible it depends of your version of grunt-contrib-less, see also Does grunt-contrib-less support --source-map-map-inline? 可能取决于您的grunt-contrib-less版本,另请参见grunt-contrib-less是否支持--source-map-map-inline? (which describes inline source maps as you describe) (它按照您的描述描述了内联源映射)

read: https://github.com/gruntjs/grunt-contrib-less 阅读: https : //github.com/gruntjs/grunt-contrib-less

set sourceMapBasepath to / . sourceMapBasepath设置为 /

Why is it a base64 output? 为什么它是base64输出? I thought it should just point to the styles.css.map file. 我认为它应该只指向styles.css.map文件。

-- -

sourceMapFilename sourceMapFilename

Type: String Default: none 类型:字符串默认值:无

Write the source map to a separate file with the given filename. 将源映射写入具有给定文件名的单独文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM