refactor: 产品大图迁移OSS,小图标本地打包,资源基址改为.env配置
This commit is contained in:
+5
-1
@@ -4,7 +4,9 @@
|
||||
* 留空表示继续使用小程序包内本地资源(/icon、/img);
|
||||
* 配置阿里云 OSS / CDN 后,所有经 assetUrl 处理的资源会自动拼接远程地址。
|
||||
*/
|
||||
export const ASSET_BASE_URL = 'https://wordcloudwechat.oss-cn-hangzhou.aliyuncs.com'
|
||||
declare const __OSS_BASE_URL__: string | undefined
|
||||
|
||||
export const ASSET_BASE_URL = typeof __OSS_BASE_URL__ !== 'undefined' ? __OSS_BASE_URL__ : ''
|
||||
|
||||
/** 把本地资源路径转成远程 URL;已经是 http(s) 或 wxfile/data 的保持不变 */
|
||||
export function assetUrl(path?: string | null): string {
|
||||
@@ -12,6 +14,8 @@ export function assetUrl(path?: string | null): string {
|
||||
if (/^(https?:|wxfile:|data:)/i.test(path)) return path
|
||||
if (!ASSET_BASE_URL) return path
|
||||
const base = ASSET_BASE_URL.replace(/\/+$/, '')
|
||||
// 小图标(/icon/*)保持本地打包,只有 /img/* 大图走 OSS
|
||||
if (!path.startsWith('/img/')) return path
|
||||
const normalized = path.startsWith('/') ? path : `/${path}`
|
||||
return `${base}${normalized}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user