grunt-css2js.js 655 B

1234567891011121314151617
  1. module.exports = function(grunt) {
  2. grunt.registerMultiTask('css2js', 'Embed CSS into JS', function() {
  3. var cssContent = grunt.task.directive(grunt.file.expandFiles(this.data.src)[0], grunt.file.read);
  4. var content =
  5. 'var css="' + cssContent + '";' +
  6. 'var cssTag = document.createElement("link");' +
  7. 'document.head = document.head || document.getElementsByTagName("head")[0];' +
  8. 'cssTag.href = "data:text/css,"+css;' +
  9. 'cssTag.rel = "stylesheet";' +
  10. 'document.head.appendChild(cssTag);';
  11. grunt.file.write(this.data.dest, content);
  12. grunt.log.writeln('File "' + this.data.dest + '" created.');
  13. });
  14. };