【发布时间】:2014-06-23 23:41:47
【问题描述】:
我是编写 grunt 插件的新手,在尝试运行它时遇到了问题:
Running "inject_css:dev" (inject_css) task
Warning: Unable to write "undefined" file (Error code: undefined). Use --force to continue.
我的插件看起来像:
'use strict';
module.exports = function(grunt) {
grunt.registerMultiTask('inject_css', 'Allows you to inject CSS into HTML files as part of the build process.', function() {
var src = grunt.file.expand(this.data.src);
var text = '';
if (src) {
src.forEach(function (script) {
text += grunt.file.read(script);
});
} else {
grunt.log.error('Please specify a file to inject into the html.');
return;
}
this.files.forEach(function (file) {
grunt.file.write(file.dest, grunt.file.read(file.src).replace('<!-- inject -->', '<style type="text/css">' + text + '</style>'));
grunt.log.ok('File injected'.blue + ' into ' + file.dest);
});
});
};
当尝试在我的 gruntfile 中调用它时,我使用了以下配置:
inject_css: {
dev: {
files:{
'static/test/test.html': 'test.html'
},
src: 'static/less/form.less'
}
}
任何想法我做错了什么?
【问题讨论】:
标签: javascript gruntjs npm