This is not a new function supported by OSChina, but I’m just aware of that yesterday. Long time ago, I had once made a choice whether to use github or OSChina to be the repository storing my public code, and I finally use github later due to the fact that I found OSChina seems to have to function like github Pages. You know, as I front end developer, it’s import to show not both your code but also its visual display to others. Therefore, functions like github pages are very meaningful to me and it’s also very convenient. Without functions like github pages, I will need to build my code and then use FTP/SFTP tools like FileZilla to upload my frontend static files to my server. If you change your code in high frequency, you will find this way quite time-wasting. Whereas if you use github pages, all you need to do after rebuild your code is type one line’s command in your command line tools and press enter button ^_^.
目录
Using Github Pages
Right. There is a npm package called “gh-pages”. If your built files are stored in a folder named “src” in the root directory of your project. You can add one custom script in your package.json file like below:
"scripts": { "dev": "node build/dev-server.js", "build": "node build/build.js", "deployToGit": "gh-pages -d dist", "test": "echo \"Error: no test specified\" && exit 1" },
The scripts “gh-pages -d dist” will deploy all your code under dist folder to a remote branch in github called “gh-pages”, and then you can visit your project online through link like “http://yakima-teng.github.io/demos/” in which “yakima-teng” should be replaced by your github user name and “demos” should be replaced by your project name of your github repository.
Using OSChina Pages
Although there is strings “gh” in the name of the npm package “gh-pages”, this package is also available to use for OSChina Pages. As per the official npm website for this package, you can find many custom options. In short, if:
- your files need to be visited online are all built to a folder called dist in your project root,
- you want to use a remote branch called “oschina-pages” to be used for online display purpose,
- your remote git repository address is “https://git.oschina.net/yakima/demos.git”.
You can add a script alias (short name) “deployToOSChina” in your package.json file like below:
"scripts": { "dev": "node build/dev-server.js", "build": "node build/build.js", "deployToGit": "gh-pages -d dist", "deployToOSChina": "gh-pages -d dist -b oschina-pages -o oschina -r https://git.oschina.net/yakima/demos.git", "test": "echo \"Error: no test specified\" && exit 1" },
Yakima Teng,
August 28, 2017,
In Shanghai, China