这只是为您提供解决方法的提示。这不是一个详细的分步回答。
如果您已经使用 Grunt,您可以使用 this grunt plugin。
它是 msdeploy.exe 命令的包装,因此您需要了解 here。
在所有这些之前,您需要在您的服务器上安装 Web Deploy。有一些关于此的策略和帖子。我选择使用Remote Agent方式。
我在部署之前手动创建了网站(还不知道如何远程执行此操作。正在努力。这就是我发现这个问题的原因)。然后我只需同步我计算机中的目录(您的 /dist 文件夹)和远程服务器中的路径。
这是我的 Gruntfile.js 的一部分,在 grunt.initConfig() 中定义了 2 个示例
“备份”将当前远程目录保存在一个包(zip 文件)中。
第二个名为“Oper”的任务会同步您当前位于
上的构建
msdeploy: {
backup: {
options: {
verb: "sync",
source: {
dirPath: '<%= deploy.Config.basePathOper %><%=deploy.Oper.Web %>,computerName=<%=deploy.Config.computerName %>,username=<%=deploy.Config.username %>,password=<%= deploy.Config.password %>'
},
dest: {
package: '<%= deploy.Config.basePathOper %>\\backups\\web_' + grunt.template.today("yyyy-mm-dd-HH-MM-ss") + '.zip,computerName=<%=deploy.Config.computerName %>,username=<%=deploy.Config.username %>,password=<%= deploy.Config.password %>'
}
}
},
Oper: {
options: {
verb: 'sync',
source: {
dirPath: process.cwd() + '\\<%= yeoman.dist %>'
},
dest: {
dirPath: '<%= deploy.Config.basePathOper %><%=deploy.Oper.Web %>,computerName=<%=deploy.Config.computerName %>,username=<%=deploy.Config.username %>,password=<%= deploy.Config.password %>'
}
}
}
我创建的任务看起来像这样
grunt.registerTask('deploy', function (target) {
if (target === 'Oper') {
grunt.task.run([
'msdeploy:backup',
'msdeploy:Oper'
]);
}
});
别忘了加载插件:
grunt.loadNpmTasks('grunt-msdeploy');