1

例如,我有index.css包含指向另一个 css 文件的链接:

@import "http://<some_url>/bootstrap.css";
@import "http://<some_url>/plugin.css";
@import "app.css";

可以将这些文件与 Grunt JS 连接起来吗?

4

2 回答 2

2

查看 Grunt API,文件内容似乎只适用于本地文件。 http://gruntjs.com/api/grunt.file

此外,我在源代码中没有看到任何解析 CSS 文件以查找导入的内容。

要将它们连接在一起:

我建议您在本地下载文件,将它们放在您常用的 css 文件夹中,然后像往常一样使用 Grunt concat。

然后,在使用 grunt 构建之前,我会使用 wget 编写一个小脚本来下载这些依赖项的新副本。

于 2012-11-28T11:14:39.663 回答
0

我知道自从被问到这个问题已经有一段时间了,但是我在尝试做类似的事情时遇到了它。这是使用 grunt 任务从 url 保存文件的一种方法。

module.exports = function(grunt) {
  'use strict'; 
  var http = require('http');

  grunt.initConfig({
    watch: {
      scripts: {
        files: ['**/*.cfc'],
        tasks:['saveURL']
      }
    },
    open:{
      error:{
        path:'http://<server>/rest/error.html' 
      }
    }
  });


  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-open');


  grunt.registerTask('default', ['watch']);

  grunt.registerTask('saveURL', 'Write stuff to a file', function() {
    var done = this.async();
    var reloadurl = 'http://<server>/rest/index.cfm?rl';

    grunt.log.writeln('Loading URL:' + reloadurl + ' ...');

    http.get(reloadurl, function(res) {
      var pageData = "";
      if(res.statusCode != '200'){
        //if we don't have a successful response queue the open:error task
        grunt.log.error('Error Reloading Application!: ' + res.statusCode);
        grunt.task.run('open:error');
      }
      res.setEncoding('utf8');

      //this saves all the file data to the pageData variable
      res.on('data', function (chunk) {
        pageData += chunk;
      });

      res.on('end', function(){
        //This line writes the pageData variable to a file
        grunt.file.write('error.html', pageData)
        done();
      });
    }).on('error', function(e) {
      console.log("Got error: " + e.message);
      done(false);
    });
  });

};
于 2013-03-01T16:04:47.233 回答