@lark-apaas/fullstack-rspack-preset 1.0.26-alpha.1 → 1.0.26-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,15 +39,24 @@ class SlardarPerformanceMonitorPlugin {
|
|
|
39
39
|
globalName: this.options.globalName,
|
|
40
40
|
});
|
|
41
41
|
const teaSnippet = getTeaScriptContent();
|
|
42
|
-
if (!snippet)
|
|
42
|
+
if (!snippet) {
|
|
43
43
|
return data;
|
|
44
|
+
}
|
|
44
45
|
// 创建 Slardar 脚本标签对象
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
let slardarTags;
|
|
47
|
+
if (Array.isArray(snippet)) {
|
|
48
|
+
slardarTags = snippet;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
slardarTags = [
|
|
52
|
+
{
|
|
53
|
+
tagName: 'script',
|
|
54
|
+
voidTag: false,
|
|
55
|
+
innerHTML: snippet,
|
|
56
|
+
attributes: {},
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
51
60
|
// 创建 Tea 脚本标签对象
|
|
52
61
|
const teaTag = {
|
|
53
62
|
tagName: 'script',
|
|
@@ -62,11 +71,15 @@ class SlardarPerformanceMonitorPlugin {
|
|
|
62
71
|
tag.attributes.src.includes('main.js'));
|
|
63
72
|
if (mainJsIndex !== -1) {
|
|
64
73
|
// 在 main.js 之前插入 Slardar 脚本
|
|
65
|
-
data.headTags
|
|
74
|
+
data.headTags = [
|
|
75
|
+
...data.headTags.slice(0, mainJsIndex),
|
|
76
|
+
...slardarTags,
|
|
77
|
+
...data.headTags.slice(mainJsIndex),
|
|
78
|
+
];
|
|
66
79
|
}
|
|
67
80
|
else {
|
|
68
81
|
// 如果没找到 main.js,插入到 headTags 最前面
|
|
69
|
-
data.headTags.
|
|
82
|
+
data.headTags = slardarTags.concat(data.headTags);
|
|
70
83
|
data.headTags.unshift(teaTag);
|
|
71
84
|
}
|
|
72
85
|
return data;
|
|
@@ -82,38 +95,50 @@ exports.default = SlardarPerformanceMonitorPlugin;
|
|
|
82
95
|
function getSlardarScriptContent(option = {}) {
|
|
83
96
|
const bid = option.bid || 'apaas_ai';
|
|
84
97
|
const globalName = option.globalName || 'KSlardarWeb';
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
98
|
+
return [
|
|
99
|
+
{
|
|
100
|
+
tagName: 'script',
|
|
101
|
+
voidTag: false,
|
|
102
|
+
attributes: {
|
|
103
|
+
src: `https://lf3-short.ibytedapm.com/slardar/fe/sdk-web/browser.cn.js?bid=${bid}&globalName=${globalName}`,
|
|
104
|
+
crossOrigin: 'anonymous',
|
|
105
|
+
defer: true,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
tagName: 'script',
|
|
110
|
+
voidTag: false,
|
|
111
|
+
innerHTML: `
|
|
112
|
+
// 添加 onload 事件处理
|
|
113
|
+
slardarScript.onload = function() {
|
|
114
|
+
// 脚本加载完成后执行初始化
|
|
115
|
+
if (window.${globalName}) {
|
|
116
|
+
window.${globalName}('init', {
|
|
117
|
+
bid: '${bid}',
|
|
118
|
+
// 四种类型:dev/boe/pre/online
|
|
119
|
+
env: 'online',
|
|
120
|
+
});
|
|
121
|
+
window.${globalName}('start');
|
|
122
|
+
}
|
|
123
|
+
};
|
|
90
124
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// 将脚本添加到页面
|
|
110
|
-
document.head.appendChild(slardarScript);
|
|
111
|
-
|
|
112
|
-
// 添加 TTI 监控脚本
|
|
113
|
-
const performanceScript = document.createElement('script');
|
|
114
|
-
performanceScript.src = 'https://sf3-scmcdn-cn.feishucdn.com/obj/unpkg/byted/performance/0.1.2/dist/performance.iife.js';
|
|
115
|
-
document.head.appendChild(performanceScript);
|
|
116
|
-
`;
|
|
125
|
+
// 添加错误处理
|
|
126
|
+
slardarScript.onerror = function() {
|
|
127
|
+
console.warn('Failed to load Slardar script');
|
|
128
|
+
};
|
|
129
|
+
`,
|
|
130
|
+
attributes: {},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
tagName: 'script',
|
|
134
|
+
voidTag: false,
|
|
135
|
+
attributes: {
|
|
136
|
+
src: 'https://sf3-scmcdn-cn.feishucdn.com/obj/unpkg/byted/performance/0.1.2/dist/performance.iife.js',
|
|
137
|
+
crossOrigin: 'anonymous',
|
|
138
|
+
defer: true,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
];
|
|
117
142
|
}
|
|
118
143
|
// 获取 tea sdk 脚本
|
|
119
144
|
function getTeaScriptContent() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-rspack-preset",
|
|
3
|
-
"version": "1.0.26-alpha.
|
|
3
|
+
"version": "1.0.26-alpha.3",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"patches",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@lark-apaas/miaoda-inspector-babel-plugin": "^1.0.0",
|
|
36
36
|
"@lark-apaas/miaoda-inspector-jsx-runtime": "^1.0.0",
|
|
37
37
|
"@rspack/plugin-react-refresh": "^1.5.1",
|
|
38
|
-
"@swc/plugin-styled-jsx": "^
|
|
38
|
+
"@swc/plugin-styled-jsx": "^11.0.0",
|
|
39
39
|
"clsx": "^2.1.1",
|
|
40
40
|
"colorjs.io": "^0.5.2",
|
|
41
41
|
"dotenv": "^16.4.5",
|