chore: bump version to v0.9.64 and enhance i18n support for Shadow DOM mode
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vocechat-web",
|
"name": "vocechat-web",
|
||||||
"version": "0.9.63",
|
"version": "0.9.64",
|
||||||
"homepage": "https://voce.chat",
|
"homepage": "https://voce.chat",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@metamask/onboarding": "^1.0.1",
|
"@metamask/onboarding": "^1.0.1",
|
||||||
|
|||||||
+14
-1
@@ -17,7 +17,20 @@ const local_dev = `http://localhost:3000`;
|
|||||||
const dev_origin = process.env.REACT_APP_OFFICIAL_DEMO ? official_dev : local_dev;
|
const dev_origin = process.env.REACT_APP_OFFICIAL_DEMO ? official_dev : local_dev;
|
||||||
|
|
||||||
// const local_dev = `https://im.ttt.td`;
|
// const local_dev = `https://im.ttt.td`;
|
||||||
export const BASE_ORIGIN = process.env.REACT_APP_RELEASE ? `${location.origin}` : dev_origin;
|
// 在 widget 模式下,使用 widget 脚本所在的 origin
|
||||||
|
const getBaseOrigin = () => {
|
||||||
|
if (process.env.REACT_APP_RELEASE) {
|
||||||
|
// 检查是否有 widget origin(Shadow DOM 模式)
|
||||||
|
const widgetOrigin = (window as any).__VOCECHAT_WIDGET_ORIGIN__;
|
||||||
|
if (widgetOrigin) {
|
||||||
|
return widgetOrigin;
|
||||||
|
}
|
||||||
|
return location.origin;
|
||||||
|
}
|
||||||
|
return dev_origin;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const BASE_ORIGIN = getBaseOrigin();
|
||||||
export const IS_OFFICIAL_DEMO = BASE_ORIGIN === official_dev;
|
export const IS_OFFICIAL_DEMO = BASE_ORIGIN === official_dev;
|
||||||
|
|
||||||
const BASE_URL = `${BASE_ORIGIN}/api`;
|
const BASE_URL = `${BASE_ORIGIN}/api`;
|
||||||
|
|||||||
@@ -66,6 +66,14 @@ i18n
|
|||||||
returnNull: false,
|
returnNull: false,
|
||||||
// for backend middleware
|
// for backend middleware
|
||||||
backend: {
|
backend: {
|
||||||
|
loadPath: (() => {
|
||||||
|
// 在 Shadow DOM 模式下,使用 widget.js 所在的 origin 来加载翻译文件
|
||||||
|
const widgetOrigin = (window as any).__VOCECHAT_WIDGET_ORIGIN__;
|
||||||
|
if (widgetOrigin) {
|
||||||
|
return `${widgetOrigin}/locales/{{lng}}/{{ns}}.json`;
|
||||||
|
}
|
||||||
|
return '/locales/{{lng}}/{{ns}}.json';
|
||||||
|
})(),
|
||||||
queryStringParams: { v: pkg.version }
|
queryStringParams: { v: pkg.version }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// 在 Shadow DOM 模式下,动态设置 webpack 的 publicPath
|
// 在 Shadow DOM 模式下,动态设置 webpack 的 publicPath
|
||||||
// 这样 webpack 运行时加载的动态资源(如代码分割的 chunk)会从正确的源服务器加载
|
// 这样 webpack 运行时加载的动态资源(如代码分割的 chunk)会从正确的源服务器加载
|
||||||
|
let widgetOrigin = '';
|
||||||
if (typeof document !== 'undefined') {
|
if (typeof document !== 'undefined') {
|
||||||
const currentScript = document.currentScript as HTMLScriptElement;
|
const currentScript = document.currentScript as HTMLScriptElement;
|
||||||
if (currentScript && currentScript.src) {
|
if (currentScript && currentScript.src) {
|
||||||
@@ -9,6 +10,9 @@ if (typeof document !== 'undefined') {
|
|||||||
const scriptPath = scriptUrl.pathname.substring(0, scriptUrl.pathname.lastIndexOf('/') + 1);
|
const scriptPath = scriptUrl.pathname.substring(0, scriptUrl.pathname.lastIndexOf('/') + 1);
|
||||||
// 设置为脚本所在的完整目录路径
|
// 设置为脚本所在的完整目录路径
|
||||||
__webpack_public_path__ = scriptUrl.origin + scriptPath;
|
__webpack_public_path__ = scriptUrl.origin + scriptPath;
|
||||||
|
// 保存 origin 供 i18n 使用
|
||||||
|
widgetOrigin = scriptUrl.origin;
|
||||||
|
(window as any).__VOCECHAT_WIDGET_ORIGIN__ = widgetOrigin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to set webpack public path:', e);
|
console.warn('Failed to set webpack public path:', e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user