As a newcomer to writing grunt plugins, I've encountered an issue when attempting to run it:
Running "inject_css:dev" (inject_css) task
Warning: Unable to write "undefined" file (Error code: undefined). Use --force to continue.
The structure of my plugin is as follows:
'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);
});
});
};
When calling the plugin in my gruntfile, I have configured it like this:
inject_css: {
dev: {
files:{
'static/test/test.html': 'test.html'
},
src: 'static/less/form.less'
}
}
Can someone point out where I might be going wrong?