Grunt concat files on a different domain or on different server

北城以北 提交于 2019-12-02 01:51:01

问题


Edit working version and explanation

I want to concat files from different server into my destination folder using grunt, and grunt-concat and with something like that:

  concat: {
      options: {
        separator: ';'
      },
      dist: {
        src: ['dev.staticcontent.com/media/clientcontent/library/*.js', 'js/*.js'],       
        dest: 'dist/<%= pkg.name %>.js'
      }
    },

each time I tried, I received no error from grunt, but my dist/marketing-home.js file is empty... Like it didn't find anything.

Console:

C:\Project\My>grunt 
Running "jshint:files" (jshint) task
>> 1 file lint free.

Running "concat:dist" (concat) task
File dist/marketing-home.js created.

Running "uglify:dist" (uglify) task

Done, without errors.

New Version

After the help of Kris, I was able to do it without passing through the web using grunt-exec and doing using COPY or XCOPY shell command.

ex.

   exec: {
     copy : {
        cmd: function () {
               var path = "\\\\dev-server123\\WebSites\\Static_Contents\\Media\\clientcontent";
               return "copy dist\\*.min.js " + path + " /y";
        }
     }
   }

回答1:


Doesn't look like concat task handles absolute paths or files from remote locations. However I was able to get it to work using curl task combined with the concat task.

EXAMPLE:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    curl: {
      'download/jquery.js': 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js',
    },
    concat: {
        js: {
            src: ['download/jquery.js'],
            dest: 'output/test.js'
        },
    }
  });

  grunt.loadNpmTasks('grunt-curl');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.registerTask('default', ['curl', 'concat']);
};

DEMO DIRECTORY STRUCTURE:

I used this Node Module Package for CURL. https://github.com/twolfson/grunt-curl, there may be better ones out there. But this one seemed to work fine.



来源:https://stackoverflow.com/questions/27364948/grunt-concat-files-on-a-different-domain-or-on-different-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!