5

我正在尝试在我的项目中使用源地图。我正在使用LESS ,使用grunt-contrib-less与Grunt编译

这是我在 gruntfile.js 上的代码:

less: {
  development: {
    options: {
      paths: ["assets-src"],
      // LESS source maps
      // To enable, set sourceMap to true and update sourceMapRootpath
         based on your install
      sourceMap: true,
      sourceMapFilename: 'assets-src/desktop/css/desktop.css.map',
      sourceMapRootpath: 'assets-dist/desktop/css/'
    },
    files : {
      "assets-src/desktop/css/desktop.css" :
      [
      "assets-src/desktop/less/reset.less",
      "assets-src/desktop/less/variables.less",
      "assets-src/desktop/less/mixins.less" 
      ]
    }
  }
 }

这是我拥有的文件结构:

在此处输入图像描述

我在定义sourceMapRootpath 时遇到问题。我尝试将所有 .LESS 文件所在的文件夹放在同一个文件夹中,但没有发生任何事情,与使用 .CSS 文件所在的文件夹相同。

对此有任何想法吗?

谢谢!塞巴

4

2 回答 2

6

I just solved this issue by setting to true the parameter "outputSourceFiles". You have to add this param. Because the sourceMapping of LESS is related to your express server root. I'm almost sure yours is assets-dist. By the way, you should have this in your gruntfile :

enter code here
      outputSourceFiles: true, // with this param you'll have your less in your map and you can see it
      sourceMap: true,
      sourceMapFilename: 'path/to/your/map', 
      sourceMapURL: '/complete/url/to/your/map', 
      sourceMapBasepath: 'public'
于 2014-03-16T20:13:09.077 回答
0

我将假设您使用的是过时的版本grunt-contrib-less,因为我遇到了同样的问题。查看发布历史,最近才在 LESS 中添加源映射支持。

检查您的package.json文件,并确保您的grunt-contrib-less版本将采用最新0.9.0版本,然后使用npm install.

于 2014-01-15T17:16:02.747 回答