我有多个 .less 文件,我希望将它们处理为匹配的 .css,每个文件的 sourceMaps 都与源位于同一文件夹中。
这有多难?
我用 less 直接执行此操作没有问题,但无法弄清楚如何在 grunt-contrib-less 中执行此操作,因为它似乎希望 sourceMap 文件名成为单个硬编码值。
这是我的 grunt 文件:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
watch: {
options: {
livereload: true,
},
css: {
files: ['./core/theme/**/*.less'],
tasks: ['less'],
options: {
spawn: false
},
},
},
less: {
all: {
src: ['./core/theme/**/*.less'],
expand: true,
dest: "./core/theme/",
options:{sourceMap:true},
rename:function (dest, src) {
return src.substring(0, src.lastIndexOf('.'))+'.css';
}
},
}
});
// on watch events configure less:all to only run on changed file
grunt.event.on('watch', function(action, filepath) {
grunt.config('less.all.src', filepath);
});
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-less");
grunt.registerTask("default", ["less"]);
};
TIA