Home > Article > Web Front-end > How to use shelljs to implement automated front-end deployment
The content of this article is about how to use shelljs to realize automatic deployment of the front-end. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Scenario
In the front-end development process, you must often use the following commands:
npm run build git add . git commit -m 'commit' git push
I am using vue -cli
When writing my personal blog, deploy it to coding pages
. The reason why github pages
is not used is purely because it is slow. . . Every time I deploy, I have to type the above command again, which is really painful for me. It would be much better if you could perform all the above tasks with one command.
Don’t say much, just do what you say.
2. Shelljs
This library allows us to execute shell commands in js
files. Please refer to the documentation for details.
npm install [-g] shelljs
There are two ways to use it, one is global mode (corresponding to global installation), and the other is local mode. Look at the use case below to know the difference between the two.
3. Use
to create a new file shell.js
in the root directory. The content is as follows:
//局部模式 var shell = require('shelljs'); //全局模式下,就不需要用shell开头了。 //require('shelljs/global'); if (shell.exec('npm run build').code !== 0) {//执行npm run build 命令 shell.echo('Error: Git commit failed'); shell.exit(1); } //由于我的用另外一个仓库存放dist目录,所以这里要将文件增量复制到目标目录。并切换到对应目录。 shell.cp ('-r', './dist/*', '../../Rychou'); shell.cd('../../Rychou'); shell.exec('git add .'); shell.exec("git commit -m 'autocommit'") shell.exec('git push')
At this time, Just execute node shell.js
in the root directory.
This is just the simplest use case.
4. Make it more convenient
Add in package.json
:
"script":{ + "push":"node ./shell.js" }
in the root directory Execute npm run push
and it will be done.
Related recommendations:
Automated deployment of Hadoop cluster based on Kickstart
php Laravel method to achieve deployment automation
php5.3.10 Automated Deployment Script First Edition_PHP Tutorial
The above is the detailed content of How to use shelljs to implement automated front-end deployment. For more information, please follow other related articles on the PHP Chinese website!