我有以下gruntfile.js:
module.exports = function(grunt) {
require('jit-grunt')(grunt);
grunt.initConfig({
uglify: {
options: {
manage: false
},
my_target: {
files: [{
expand: true,
cwd: 'assets/js',
src: '*.js',
dest: 'assets/js/min'
}]
},
},
less: {
development: {
options: {
compress: true,
yuicompress: true,
optimization: 2
},
files: [
{
expand: true, // Recursive
cwd: "assets", // The startup directory
src: ["**/*.less"], // Source files
dest: "assets/", // Destination
ext: ".css" // File extension
}
]
}
},
watch: {
styles: {
files: ['assets/**/*.less', 'assets/js/*.js'], // which files to watch
tasks: ['less', 'newer:uglify'],
options: {
nospawn: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-newer');
grunt.registerTask('default', ['less', 'watch', 'newer:uglify']);
};
以下路径分布:
| assets
|-- folder-1
|-- less
|-- folder-2
|-- less
使用当前gruntfile.js
,我的输出是less文件夹的子级别:
| assets
|-- folder-1
|-- less
|-- css
|-- folder-2
|-- less
|-- css
但它应该在LESS文件的同一级别上。例如:
| assets
|-- folder-1
|-- less
|-- css
|-- folder-2
|-- less
|-- css
有关如何修改gruntfile.js
的任何想法吗?这可能吗?
答案 0 :(得分:2)
如果我理解正确,您需要一个css /文件夹作为每个文件夹{x} /文件夹中less /文件夹的兄弟。
这可以通过将rename属性添加到您的less task config:
来完成files: [
{
expand: true, // Recursive
cwd: "assets", // The startup directory
src: ["**/*.less"], // Source files
dest: "assets/", // Destination
ext: ".css", // File extension
rename: function (dest, src) {
return (dest + src.replace('less/', 'css/'));
}
}
]