2013-06-02 42 views
7

我试图在从Sass编译时自动上传.css文件。这是我在Gruntfile.js得:Grunt - 当文件被改变时观察文件和SFTP

module.exports = function(grunt) { 

    // Project configuration. 
    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 
    watch: { 
     coffee: { 
     files: ['**/*.coffee'], 
     tasks: ['coffee'] 
     }, 
     scripts: { 
     files: ['**/*.scss'], 
     tasks: ['compass'] 
     }, 
     sftp: { 
     files: ['**/*.css'], 
     tasks: ['sftp-deploy'] 
     } 
    }, 
    coffee: { 
     compile: { 
     files: { 
      'testing.js': 'testing.coffee' 
     } 
     } 
    }, 
    compass: { 
     dist: { 
     options: { 
      config: 'config.rb' 
     } 
     } 
    }, 

    'sftp-deploy': { 
     build: { 
     auth: { 
      host: 'example.com', 
      port: 22, 
      authKey: 'key2' 
     }, 
     src: 'styles/', 
     dest: 'styles/', 
     exclusions: ['**/.DS_Store'], 
     server_sep: '/' 
     } 
    } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.loadNpmTasks('grunt-contrib-coffee'); 
    grunt.loadNpmTasks('grunt-contrib-compass'); 
    grunt.loadNpmTasks('grunt-sftp-deploy'); 


    // Default task(s). 
    grunt.registerTask('default', ['watch']); 

}; 

它编译.css但似乎并没有把它上传。有任何想法吗?

+0

'config.rb'输出已编译的'css'到什么目录? –

+0

你不应该在本地执行此操作,然后只在运行构建步骤时才推送? –

回答

1

我正在尝试使用grunt-sftp做几乎完全相同的事情,并遇到类似的错误。日志记录是不是最好的,所以我结束了使用grunt-shell和刚跑scp在编译:

watch: { 
    tumblr: { 
     files:['sass/*.scss', 'sass/*/*.scss'], 
     tasks: [ 'compass:tumblr', 'shell:tumblr' ] 
    } 
}, 

shell: { 
    tumblr: { 
    command: 'scp -P 2222 -r stylesheets "[email protected]:/var/www/foo/directory"' 
    } 
} 

这工作就像一个魅力。

2

我想确认下面的grunt-ssh(https://github.com/andrewrjones/grunt-ssh)任务配置对我来说工作得很好。请注意,grunt接受可能有助于调试的--verbose选项。请注意,从v0.6.2开始,grunt-ssh SFTP任务似乎不支持sshconfig语法,这在帮助页面中不是很清楚。

sftpCredentials: grunt.file.readJSON('sftp-credentials.json'), 
    sftp: { 
     deploy: { 
      files: { 
       "./": "deploy/**" 
      }, 
      options: { 
       "path": "<%= sftpCredentials.path %>", 
       "host": "<%= sftpCredentials.host %>", 
       "username": "<%= sftpCredentials.username %>", 
       "port": "<%= sftpCredentials.port %>", 
       "password": "<%= sftpCredentials.password %>", 
       "srcBasePath": "deploy/", 
       "createDirectories": true 
      } 
     } 
    } 
+0

使用'grunt-ssh',您如何设置手表以便仅上载已更改的文件? – mpen

+0

我从手动启动的grunt任务上传文件(我用它将我的新版本上传到一个新的空文件夹中)。我看到你已经为此创建了单独的问题,希望最终能够在那里回答! :) – sbat

相关问题