0

我正在使用 grunt-contrib-less 来编译更少的文件。

我已经在项目文件夹的根目录本地安装了 grunt。

css 文件位于qa1/avinash/html5/phase1/css/项目文件夹根目录的路径中。

所以这是我为cwd(当前工作目录)指定的路径,src以及destgrunt-less 任务的参数。编译 css 和 source map 没有问题。

我面临的唯一问题是源映射是在 gruntfile 的同一文件夹中生成的。但我生成的 css 在dest我指定的路径上。由于 css 和源映射位于不同的位置,我必须手动编辑源映射中的较少路径引用并将其带到生成的 css 目录。或用于sourceMapURL指定源地图位置../../../../../style.css.map(向后)。两种方式都不方便。

那么任何人都可以帮助我如何指定源映射输出目标路径,就像我们为生成的css指定的目标路径一样

sourceMapDest: 'qa1/avinash/html5/phase1/css/'

--

目前使用的 Gruntfile.js:

module.exports = function(grunt) {
    grunt.initConfig({
        less: {
            options: {
                sourceMap:true,
                sourceMapFilename: "style.css.map",
                sourceMapURL: '../../../../../style.css.map'
            },
            src: {
                // no need for files, the config below should work
                expand: true,
                cwd:    "qa1/avinash/html5/phase1/css/",
                src:    "style.less",
                dest:   "qa1/avinash/html5/phase1/css/",
                ext:    ".css"
            }
        },
        watch: {
            js: {
                files: ['qa1/avinash/html5/phase1/css/'],
                tasks: ['default'],
            }
        }
    });
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.registerTask('default', ['less']);
};
4

1 回答 1

1

sourceMapFilename选项也可能包括路径部分。即只需将其更改为:

sourceMapFilename: "qa1/avinash/html5/phase1/css/style.css.map"
于 2014-12-17T12:58:42.670 回答