@lark-apaas/miaoda-presets 1.0.0 → 1.0.1
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.
package/lib/recommend/eslint.js
CHANGED
|
@@ -27,17 +27,30 @@ exports.default = {
|
|
|
27
27
|
'import/named': 'error', // 检查命名导入是否存在
|
|
28
28
|
// 效果相关:模型不会
|
|
29
29
|
'no-constant-binary-expression': 'off', // 不强制使用常量二进制表达式
|
|
30
|
-
// 效果相关:希望模型使用内置 logger
|
|
31
30
|
'no-restricted-syntax': [
|
|
32
31
|
'error',
|
|
32
|
+
// 效果相关:希望模型使用内置 logger 而不是 console
|
|
33
33
|
{
|
|
34
34
|
selector: "CallExpression[callee.object.name='console'][callee.property.name=/^(log|warn|info|debug|trace)$/]",
|
|
35
35
|
message: 'Avoid using console.log, console.warn, etc. Use `@byted/spark-framework/logger` instead.',
|
|
36
36
|
},
|
|
37
|
+
// 禁用BOM方法alert和confirm,及不推荐使用同名方法
|
|
38
|
+
{
|
|
39
|
+
message: "Please don't use window.alert, use `Dialog` component instead for better user experience and consistency",
|
|
40
|
+
selector: "MemberExpression[object.name='window'][property.name='alert']",
|
|
41
|
+
},
|
|
37
42
|
{
|
|
38
43
|
message: "Please don't use window.confirm, use `Dialog` component instead for better user experience and consistency",
|
|
39
44
|
selector: "MemberExpression[object.name='window'][property.name='confirm']",
|
|
40
45
|
},
|
|
46
|
+
{
|
|
47
|
+
message: "Please don't use alert. It may conflict with window.alert BOM method, use `Dialog` component instead for better user experience and consistency",
|
|
48
|
+
selector: "CallExpression[callee.name='alert']",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
message: "Please don't use confirm. It may conflict with window.confirm BOM method, use `Dialog` component instead for better user experience and consistency",
|
|
52
|
+
selector: "CallExpression[callee.name='confirm']",
|
|
53
|
+
},
|
|
41
54
|
],
|
|
42
55
|
},
|
|
43
56
|
};
|
package/lib/recommend/rspack.js
CHANGED
|
@@ -8,6 +8,8 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const core_1 = __importDefault(require("@rspack/core"));
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
10
|
const RouteParserPlugin = require('../rspack-plugins/route-parser-plugin');
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
12
|
+
const SlardarPerformanceMonitorPlugin = require('../rspack-plugins/slardar-performance-monitor-plugin');
|
|
11
13
|
// eslint-disable-next-line max-lines-per-function
|
|
12
14
|
function createRecommendRspackConfig(options) {
|
|
13
15
|
const { enableReactRefresh = false, isDev = true, needRoutes = true, runtimeMode = 'fullstack', } = options;
|
|
@@ -120,6 +122,8 @@ function createRecommendRspackConfig(options) {
|
|
|
120
122
|
new core_1.default.optimize.LimitChunkCountPlugin({
|
|
121
123
|
maxChunks: 1,
|
|
122
124
|
}),
|
|
125
|
+
// 全栈模式下,增加性能监控上报脚本注入
|
|
126
|
+
runtimeMode === 'fullstack' ? new SlardarPerformanceMonitorPlugin() : undefined,
|
|
123
127
|
// 开发环境下,解析路由
|
|
124
128
|
isDev &&
|
|
125
129
|
needRoutes &&
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 加载性能监控脚本
|
|
4
|
+
* @param {object} option
|
|
5
|
+
* @param {string} [option.bid='apaas_ai']
|
|
6
|
+
* @param {string} [option.globalName='KSlardarWeb']
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
function getSlardarScript(option = {}) {
|
|
10
|
+
const bid = option.bid || 'apaas_ai';
|
|
11
|
+
const globalName = option.globalName || 'KSlardarWeb';
|
|
12
|
+
return `
|
|
13
|
+
<script>
|
|
14
|
+
// 创建 Slardar 脚本元素
|
|
15
|
+
const slardarScript = document.createElement('script');
|
|
16
|
+
slardarScript.src = 'https://lf3-short.ibytedapm.com/slardar/fe/sdk-web/browser.cn.js?bid=${bid}&globalName=${globalName}';
|
|
17
|
+
slardarScript.crossOrigin = 'anonymous';
|
|
18
|
+
|
|
19
|
+
// 添加 onload 事件处理
|
|
20
|
+
slardarScript.onload = function() {
|
|
21
|
+
// 脚本加载完成后执行初始化
|
|
22
|
+
if (window.KSlardarWeb) {
|
|
23
|
+
window.KSlardarWeb('init', {
|
|
24
|
+
bid: 'apaas_ai',
|
|
25
|
+
// 四种类型:dev/boe/pre/online
|
|
26
|
+
env: 'online',
|
|
27
|
+
});
|
|
28
|
+
window.KSlardarWeb('start');
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// 添加错误处理
|
|
33
|
+
slardarScript.onerror = function() {
|
|
34
|
+
console.warn('Failed to load Slardar script');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 将脚本添加到页面
|
|
38
|
+
document.head.appendChild(slardarScript);
|
|
39
|
+
|
|
40
|
+
// 添加 TTI 监控脚本
|
|
41
|
+
const performanceScript = document.createElement('script');
|
|
42
|
+
performanceScript.src = 'https://sf3-scmcdn-cn.feishucdn.com/obj/unpkg/byted/performance/0.1.0/dist/performance.iife.js';
|
|
43
|
+
document.head.appendChild(performanceScript);
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
class SlardarPerformanceMonitorPlugin {
|
|
49
|
+
constructor(options) {
|
|
50
|
+
this.options = options || {};
|
|
51
|
+
}
|
|
52
|
+
apply(compiler) {
|
|
53
|
+
compiler.hooks.compilation.tap('SlardarPerformanceMonitorPlugin', compilation => {
|
|
54
|
+
try {
|
|
55
|
+
// 尝试获取HtmlRspackPlugin的hooks
|
|
56
|
+
let HtmlPlugin;
|
|
57
|
+
try {
|
|
58
|
+
HtmlPlugin = require('@rspack/core').rspack.HtmlRspackPlugin;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
// 如果html-rspack-plugin不可用,尝试使用html-webpack-plugin
|
|
62
|
+
try {
|
|
63
|
+
HtmlPlugin = require('html-webpack-plugin');
|
|
64
|
+
}
|
|
65
|
+
catch (e2) {
|
|
66
|
+
console.warn('SlardarPerformanceMonitorPlugin: html-rspack-plugin or html-webpack-plugin not found');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const hooks = HtmlPlugin.getHooks(compilation);
|
|
71
|
+
// 在生成 HTML 前修改内容
|
|
72
|
+
hooks.beforeEmit.tapAsync('SlardarPerformanceMonitorPlugin', (data, cb) => {
|
|
73
|
+
const position = this.options.position ?? 'head-end';
|
|
74
|
+
const snippet = this.options.snippet ?? getSlardarScript();
|
|
75
|
+
if (!snippet)
|
|
76
|
+
return;
|
|
77
|
+
if (position === 'body-end') {
|
|
78
|
+
data.html = data.html.replace('</body>', `${snippet}\n</body>`);
|
|
79
|
+
}
|
|
80
|
+
else if (position === 'body-start') {
|
|
81
|
+
data.html = data.html.replace('<body>', `<body>\n${snippet}`);
|
|
82
|
+
}
|
|
83
|
+
else if (position === 'head-end') {
|
|
84
|
+
data.html = data.html.replace('</head>', `${snippet}\n</head>`);
|
|
85
|
+
}
|
|
86
|
+
cb(null, data);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error('Error in SlardarPerformanceMonitorPlugin:', error);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// 导出插件
|
|
96
|
+
module.exports = SlardarPerformanceMonitorPlugin;
|