Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

这句webpack 怎么理解?

 publicPath: process.env.NODE_ENV === 'production' ? './' : '/'
 
 './' : '/' 这两啥区别?最终输出位置 有区别?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

就可能项目发布后不在域名根路径。
比如域名是a.com,你的项目部署在a.com/project/目录下,默认情况下打包发布到project路径下,会有public目录,注意public目录在project路径下,而不是跟路径,这里有你的静态资源比如图片。

如果是publicPath是/,打包后资源路径会从域名根路径访问;而如果是./就是相对路径,从project路径访问。

如果发布在域名根路径./和/没有明显区别。(当然,如果是history模式,并且部署在非根路径,不该使用./)

/和./会影响打包后路由跳转、js、css、img资源的路径。

https://wintc.top/article/29


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...