欢迎光临
我们一直在努力

发布静态文件到服务器上的简化操作

Of course, you can use a client tool such as FileZilla to deploy your static files to the server. But you will certainly feel tired in the end if you need to repeat this work almost every day in case your target server is for test purpose. For me, I used webpack for local development, when I want to deploy something to the test server, I need to execute command “npm run build” first and then “npm run deployToTestServer”, it’s already very convenient, but things can be even convenient with only one command needed to type ^_^.

In your project root path, create a file named gulpfile.js, then type something like this:

Then in you package.json file, add a script:

With the above preparation, you can now type “npm run deploy” to deploy your files under local dist folder to remote server, and these files will be under the path /usr/tomcat/apache-tomcat/webapps/wechat/static/demo/dist/.

One step further, let’s install a node package called “npm-run-all” with command like:

Now let assume you use command like “npm run build” to generate your static files. Modify the package.json file and add a new line in “scripts”:

See the script “buildAndDeployToTestServer”, right? The argument “–serial” after “npm-run-all” will enable you to run several tasks one after another. In the above example, if you execute “buildAndDeployToTestServer”, the result will be the same as executing  “npm run build” first, waiting for its completion, and executing “npm run deploy”.

That’s all.

Yakima,

Nov. 17, 2017, in Shanghai, China.

赞(0) 打赏(金额可任意指定)
未经允许不得转载:峰间的云 » 发布静态文件到服务器上的简化操作
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

上海宝山顾村棉被加工店 专业加工新旧棉被

查看详情了解一下

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏