【发布时间】:2015-02-19 10:20:12
【问题描述】:
我正在使用 grunt-uncss 连接所有使用的 css 规则,并为每个 html 创建一个 css 文件。这是我目前的Gruntfile.js:
'use strict';
module.exports = function(grunt) {
/*
var src1=new Array("./4dlife/tools/experiments/index.html","./4dlife/tools/experiments/tests/test_resources_provider.html");
var dest1=new Array("1.css","2.css");
*/
var i=0;
var obj = [{'1.css':'./4dlife/tools/experiments/index.html'}, {'2.css':'./4dlife/tools/experiments/tests/test_resources_provider.html'}];
grunt.initConfig({
// Remove unused CSS across multiple files, compressing the final output
uncss: {
dist: {
files: obj
},
options: {
compress:true
}
}
});
// Load the plugins
grunt.loadNpmTasks('grunt-uncss');
// Default tasks.
grunt.registerTask('default', ['uncss']);
}
这个输出是:
运行“uncss:dist”(uncss)任务
ReferenceError:找不到变量:需要
file:///home/pc009/code/4dlife_repo/4dlife/tools/experiments/tests/test_resources_provider.html:35
ReferenceError:找不到变量:需要
file:///home/pc009/code/4dlife_repo/4dlife/tools/experiments/index.html:35 创建的文件 1.css:101.86 kB → 14.62 kB
完成,没有错误。
基本上它只对数组中的第一个文件(obj[0]) 有效,对其他文件无效。
但是,如果我将obj[0] 或obj[1] 硬编码,那么两者都可以正常工作。但我需要一次性完成,因为我需要对超过 350 个文件执行此任务。有什么建议吗?
【问题讨论】:
标签: javascript arrays node.js object gruntjs