您好,登录后才能下订单哦!
这篇文章主要讲解了vue-cli设置publicPath的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
几种设置publicPath后,再对比打包后的index.html文件
测试背景:
打包后的文件目录:
├─dist ├─css ├─img └─js index.html
一、不设置publicPath时,部署后请求路径:
http://111.222.333.444:8888/css/app.0b79487b.css
// vue.config.js module.exports = { // publicPath: '', }
<!DOCTYPE html> <html lang=en> <head> <title>test</title> <link href=/css/app.0b79487b.css rel=preload as=style> <link href=/js/app.ba2d9b8a.js rel=preload as=script> <link href=/js/chunk-vendors.e7ac9ff2.js rel=preload as=script> <link href=/css/app.0b79487b.css rel=stylesheet> </head> <body> <div id=app></div> <script src=/js/chunk-vendors.e7ac9ff2.js></script> <script src=/js/app.ba2d9b8a.js></script> </body> </html>
二、设置为/时,部署后请求路径:
http://111.222.333.444:8888/css/app.0b79487b.css
// vue.config.js module.exports = { publicPath: '/', }
<!DOCTYPE html> <html lang=en> <head> <title>test</title> <link href=/css/app.0b79487b.css rel=preload as=style> <link href=/js/app.ba2d9b8a.js rel=preload as=script> <link href=/js/chunk-vendors.e7ac9ff2.js rel=preload as=script> <link href=/css/app.0b79487b.css rel=stylesheet> </head> <body> <div id=app></div> <script src=/js/chunk-vendors.e7ac9ff2.js></script> <script src=/js/app.ba2d9b8a.js></script> </body> </html>
三、设置为./时,部署后请求路径:
http://111.222.333.444:8888/test/css/app.0b79487b.css
// vue.config.js module.exports = { publicPath: './', }
<!DOCTYPE html> <html lang=en> <head> <title>test</title> <link href=css/app.0b79487b.css rel=preload as=style> <link href=js/app.8569d42d.js rel=preload as=script> <link href=js/chunk-vendors.e7ac9ff2.js rel=preload as=script> <link href=css/app.0b79487b.css rel=stylesheet> </head> <body> <div id=app></div> <script src=js/chunk-vendors.e7ac9ff2.js></script> <script src=js/app.8569d42d.js></script> </body> </html>
四、设置为static时,部署后请求路径:
http://111.222.333.444:8888/test/static/css/app.0b79487b.css
// vue.config.js module.exports = { publicPath: 'static', }
<!DOCTYPE html> <html lang=en> <head> <title>test</title> <link href=static/css/app.0b79487b.css rel=preload as=style> <link href=static/js/app.d0717808.js rel=preload as=script> <link href=static/js/chunk-vendors.e7ac9ff2.js rel=preload as=script> <link href=static/css/app.0b79487b.css rel=stylesheet> </head> <body> <div id=app></div> <script src=static/js/chunk-vendors.e7ac9ff2.js></script> <script src=static/js/app.d0717808.js></script> </body> </html>
五、设置为./static时,部署后请求路径:
http://111.222.333.444:8888/test/static/css/app.0b79487b.css
// vue.config.js module.exports = { publicPath: './static', }
<!DOCTYPE html> <html lang=en> <head> <title>test</title> <link href=static/css/app.0b79487b.css rel=preload as=style> <link href=static/js/app.d0717808.js rel=preload as=script> <link href=static/js/chunk-vendors.e7ac9ff2.js rel=preload as=script> <link href=static/css/app.0b79487b.css rel=stylesheet> </head> <body> <div id=app></div> <script src=static/js/chunk-vendors.e7ac9ff2.js></script> <script src=static/js/app.d0717808.js></script> </body> </html>
六、设置为../static时,部署后请求路径:
http://111.222.333.444:8888/static/css/app.0b79487b.css
// vue.config.js module.exports = { publicPath: '../static', }
<!DOCTYPE html> <html lang=en> <head> <title>test</title> <link href=../static/css/app.0b79487b.css rel=preload as=style> <link href=../static/js/app.695b7ccc.js rel=preload as=script> <link href=../static/js/chunk-vendors.e7ac9ff2.js rel=preload as=script> <link href=../static/css/app.0b79487b.css rel=stylesheet> </head> <body> <div id=app></div> <script src=../static/js/chunk-vendors.e7ac9ff2.js></script> <script src=../static/js/app.695b7ccc.js></script> </body> </html>
七、设置为../时,部署后请求路径:
http://111.222.333.444:8888/css/app.0b79487b.css
// vue.config.js module.exports = { publicPath: '../', }
<!DOCTYPE html> <html lang=en> <head> <title>test</title> <link href=../css/app.0b79487b.css rel=preload as=style> <link href=../js/app.67ace555.js rel=preload as=script> <link href=../js/chunk-vendors.e7ac9ff2.js rel=preload as=script> <link href=../css/app.0b79487b.css rel=stylesheet> </head> <body> <div id=app></div> <script src=../js/chunk-vendors.e7ac9ff2.js></script> <script src=../js/app.67ace555.js></script> </body> </html>
看完上述内容,是不是对vue-cli设置publicPath的方法有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。