Upload the js generated by vue to qiniu instance, vuejs
Generally, for vue projects, we directly upload the final css js and other files to the server without cdn services.
This generally has two drawbacks,
- Increase the server bandwidth pressure. Once the access traffic goes up, the server may be suspended due to bandwidth pressure.
- Access speed may slow down in some regions
Although I know it, I am tired of manually uploading the js css file to qiniu every time.
It is a waste of time to upload qiniu cdn each time, especially when changes are made frequently.
So I went to the documents of qiniu and decided to use the scripts to solve this problem. I usedpython
Sdk implementation.
python
Install the environment on your own
First download the qiniu package
pip install qiniu
Then install the third-party dependency package glob2
pip install glob2
Upqiniu. py
#-*-Coding: UTF-8-*-from qiniu import Auth, put_file, import qiniu. configimport glob2import OS # Enter your Access Key and Secret Keyaccess_key = '*********************** 'secret _ key = *********************** '# Build an authentication object q = Auth (access_key, secret_key) # The bucket to be uploaded bucket_name = '*****' resources = glob2.glob ('dist/static/** ') def upload (path): file_name = path. replace ('dist/', '') key = file_name token = q. upload_token (bucket_name, key, 3600) localfile = '. /'+ path put_file (token, key, localfile) for r in resources: if OS. path. isfile (r): upload (r)
You need to put this script (upqiniu. py) in the directory of the same level as dist, for example:
Image.png
Access_key secret_key in the script. You can find it in your profile after logging on to qiniu:
You also need to change the publicPath of webpack to the address of qiniu.
In the vue project, you only need to change index. js under the config directory.
Although it is a little difficult to change, once and for all,
Firstnpm run build
Then python upqiniu.py
Finally index.html
Pull to the online server.
Ps: This script will dist/static/
Upload All files to qiniu, including font files and images.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.