Posting the project to the server
I created a project using a Yeoman generator generator. This includes a Grunt task named "connect" to run the project on the server. It is currently running on my localhost. Can someone explain to me how I should configure this to run on a different server?
I have a server provided by my university that I can use. Let's say it's called xyz.abc.com with username myUsername and password myPassword.
The Grunt task is defined as follows:
// The actual grunt server settings
connect: {
options: {
port: 9000,
open: true,
livereload: 35729,
// Change this to '0.0.0.0' to access the server from outside
hostname: '0.0.0.0'
},
livereload: {
options: {
middleware: function(connect) {
return [
connect.static('.tmp'),
connect().use('/bower_components', connect.static('./bower_components')),
connect.static(config.app)
];
}
}
},
test: {
options: {
open: false,
port: 9001,
middleware: function(connect) {
return [
connect.static('.tmp'),
connect.static('test'),
connect().use('/bower_components', connect.static('./bower_components')),
connect.static(config.app)
];
}
}
},
dist: {
options: {
base: '<%= config.dist %>',
livereload: false
}
}
},
source to share
If you want to deploy your application to a remote server with a grunt, you can use a similar approach as I did: add a new parameter deploy
to your yoman task, build
or create a new deploy
dedicated task using:
- grunt-ssh to execute Linux commands over SSH and send files over SFTP
- grunt-zipup to zip your local resources before sending over SFTP
For example, I have a build task that compiles / optimizes / minifies / fixes resources, where I added a parameter deploy
:
grunt.registerTask(
'build',
'Build task, does everything',
function() {
var tasks = [
[...], // custom build tasks
'zipup:buildClient' // end of build generates a zip package
];
if (grunt.option('deploy')) {
tasks.push('sshexec:cleanApacheDir'); // empty remote folder for a fresh new install
tasks.push('sftp:sendZipToApache'); // send zip through SFTP
tasks.push('sshexec:unzipToApache'); // unzip trough SSH command `unzip`
}
grunt.task.run(tasks);
}
);
See module docs for details
ps: there are many other grunt plugins you could use to do this.
source to share