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:
const gulp = require('gulp') const scp = require('gulp-scp2') gulp.task('deployToTestServer', () => { return gulp.src('dist/**/*.*') .pipe(scp({ host: '111.111.11.1', username: 'username', password: 'password', dest: '/usr/tomcat/apache-tomcat/webapps/wechat/static/demo/dist/' })) .on('error', e => { console.log(e) }) })
Then in you package.json file, add a script:
"scripts": { "deploy": "gulp deployToTestServer", // other code },
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:
npm i -D npm-run-all
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”:
"scripts": { "buildAndDeployToTestServer": "npm-run-all --serial build deploy", "deploy": "gulp deployToTestServer", "build": "node build/build.js", // ... other code },
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.
最新评论
大哥资深网民啊,01年我还在念小学。。
看着有点难过。。。
嘿嘿,谢谢老哥,也祝老哥事业蒸蒸日上。
我是你唯一的药学类友情链接网站。 作为一个80后的过来人祝福你,生活越来越好。
这篇文章,我们中学那会老师课堂上念给我们听的。
哈哈哈哈哈,没想到啊, 我有手抄版
嗯,是的
好心办坏事多了去啦
哈哈,是的,我15年末来上海写代码了,一晃三年多过去了,好快。
今天看QQ好友的时候突然看到了你的名字,想起几年前在药品国际注册群挺活跃/厉害的你,现在不见踪影了。就搜了一下,没想到你现在转行去写代码了... (刚才打漏了一句话...)