这是我的 gruntfile.js,它可以工作。
更新到 grunt-contrib-less v0.9.0 很重要
使用“XXX.css.map”而不是“XXX.map”也很重要。并且在提供了适当的 sourcebasepath 之后它起作用了。下面我将发布结果 .map 文件的摘录。
gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
less: {
development: {
options: {
compress: false,
yuicompress: false,
optimization: 2,
sourceMap: true,
sourceMapFilename: "assets/style/bootstrap.css.map",
sourceMapBasepath: "assets/style/"
},
files: {
// target.css file: source.less file
"assets/style/bootstrap.css": "assets/style/bootstrap.less"
}
}
},
watch: {
styles: {
// Which files to watch (all .less files recursively in the less directory)
files: ['assets/style/theme/**/*.less'],
tasks: ['less'],
options: {
nospawn: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
};
这是使用 lessc 生成的 .map 文件的摘录,当然可以:
{"version":3,"file":"bootstrap.css","sources":["theme/page-welcome.less","bootstrap-2.3.2/mixins.less"...
这是使用 grunt-contrib-less 0.9.0 生成的 .map 文件的摘录:
{"version":3,"sources":["theme/page-welcome.less","bootstrap-2.3.2/mixins.less","theme/page-work.less"...
亲切的问候,
斯蒂芬