@seayoo-web/scripts 3.1.11 → 4.0.0

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/dist/index.js CHANGED
@@ -1,423 +1,410 @@
1
+ import { f as getNowTime, i as getCommitInfo, r as createPageDeployTag } from "./git-C1rpf4Ed.js";
1
2
  import { join } from "node:path";
2
3
  import vue from "@vitejs/plugin-vue";
3
4
  import { visualizer } from "rollup-plugin-visualizer";
5
+ import { defineConfig, loadEnv } from "vite";
4
6
  import { finderDeploy, viteDeployPlugin } from "@seayoo-web/finder";
5
7
  import { sentryVitePlugin } from "@sentry/vite-plugin";
6
8
  import legacy from "@vitejs/plugin-legacy";
7
- import { existsSync, readFileSync, statSync, readdirSync } from "fs";
8
- import { loadEnv } from "vite";
9
- import { g as getNowTime, a as getCommitInfo, c as createPageDeployTag } from "./git-B0Cnp5wC.js";
10
- import "colors";
11
- import skipFormatting from "@vue/eslint-config-prettier/skip-formatting";
12
- import { vueTsConfigs, defineConfigWithVueTs } from "@vue/eslint-config-typescript";
13
- import { flatConfigs } from "eslint-plugin-import";
14
- import pluginVue from "eslint-plugin-vue";
9
+ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
10
+ import { defineConfig as defineConfig$1 } from "oxlint";
11
+ import { defineConfig as defineConfig$2 } from "oxfmt";
12
+ //#region src/vite.app.ts
13
+ /**
14
+ * 导出一个动态的配置工厂函数
15
+ */
15
16
  function defineAppBuildConfig(option) {
16
- const { plugins = [], build = {}, resolve = {}, ...optionReset } = option || {};
17
- const { alias, ...resolveReset } = resolve || {};
18
- return {
19
- base: "./",
20
- build: {
21
- emptyOutDir: true,
22
- outDir: join(process.cwd(), "./dist"),
23
- assetsDir: "assets",
24
- reportCompressedSize: false,
25
- sourcemap: false,
26
- ...build
27
- },
28
- plugins: [vue(), option?.visualizer ? visualizer() : null, ...plugins],
29
- resolve: {
30
- alias: {
31
- "@": join(process.cwd(), "./src"),
32
- ...alias
33
- },
34
- extensions: [".mts", ".mjs", ".ts", ".js"],
35
- ...resolveReset
36
- },
37
- ...optionReset
38
- };
17
+ const { plugins = [], build = {}, resolve = {}, ...optionReset } = option || {};
18
+ const { alias, ...resolveReset } = resolve || {};
19
+ return defineConfig({
20
+ base: "./",
21
+ build: {
22
+ emptyOutDir: true,
23
+ outDir: join(process.cwd(), "./dist"),
24
+ assetsDir: "assets",
25
+ reportCompressedSize: false,
26
+ sourcemap: false,
27
+ ...build
28
+ },
29
+ plugins: [
30
+ vue(),
31
+ option?.visualizer ? visualizer() : null,
32
+ ...plugins
33
+ ],
34
+ resolve: {
35
+ alias: {
36
+ "@": join(process.cwd(), "./src"),
37
+ ...alias
38
+ },
39
+ extensions: [
40
+ ".mts",
41
+ ".mjs",
42
+ ".ts",
43
+ ".js"
44
+ ],
45
+ ...resolveReset
46
+ },
47
+ ...optionReset
48
+ });
39
49
  }
50
+ //#endregion
51
+ //#region src/vite.lab.ts
52
+ /**
53
+ * 导出一个动态的配置工厂函数用于 lib 类工具的编译配置
54
+ *
55
+ * 默认排除 "@seayoo-web/request"、"@seayoo-web/utils"、"@seayoo-web/validator"、"@seayoo-web/combo-webview" 不打包
56
+ */
40
57
  function defineLibBuildConfig(option) {
41
- return {
42
- build: {
43
- outDir: option?.outDir || "dist",
44
- lib: {
45
- entry: join(process.cwd(), option?.rootEntry || "index.ts"),
46
- formats: ["es"],
47
- fileName: (format, entryName) => {
48
- return format === "es" ? `${entryName}.js` : `${entryName}.${format}.js`;
49
- }
50
- },
51
- rollupOptions: {
52
- external: option?.external || [/^@seayoo-web\/(?:request|utils|combo-webview|validator)/]
53
- }
54
- }
55
- };
58
+ return defineConfig({ build: {
59
+ outDir: option?.outDir || "dist",
60
+ emptyOutDir: true,
61
+ lib: {
62
+ entry: join(process.cwd(), option?.rootEntry || "index.ts"),
63
+ formats: ["es"],
64
+ fileName(format, entryName) {
65
+ return format === "es" ? `${entryName}.js` : `${entryName}.${format}.js`;
66
+ }
67
+ },
68
+ rolldownOptions: { external: option?.external || [/^@seayoo-web\/(?:request|utils|combo-webview|validator)/] }
69
+ } });
56
70
  }
57
- const EnvPrefix = "SY_";
71
+ //#endregion
72
+ //#region src/env.ts
73
+ var EnvPrefix = "SY_";
74
+ /**
75
+ * 获取构建环境配置
76
+ */
58
77
  function getBuildEnv(command, mode, requireSentryToken, ignoreSentryToken) {
59
- const envs = loadEnv(mode, process.cwd(), EnvPrefix);
60
- const envConfig = {
61
- command,
62
- stamp: getNowTime(),
63
- page: "",
64
- mode: "",
65
- deployUser: "",
66
- deployKey: "",
67
- viteEnvs: envs
68
- };
69
- envConfig.mode = mode || "preview";
70
- const t = `${EnvPrefix}DEPLOY_TO`;
71
- const s = `${EnvPrefix}SENTRY_AUTH_TOKEN`;
72
- const u = `${EnvPrefix}DEPLOY_USER`;
73
- const k = `${EnvPrefix}DEPLOY_KEY`;
74
- const p = `${EnvPrefix}SERVER_PORT`;
75
- const paths = process.cwd().replace(/\\/g, "/").split("/");
76
- const execDirWithPackage = paths.slice(-2).join("/");
77
- const execDir = paths.slice(-1)[0];
78
- const packageFile = join(process.cwd(), "./package.json");
79
- if (!existsSync(packageFile)) {
80
- console.error("执行代码有误,没有找到 package.json".red);
81
- process.exit(1);
82
- }
83
- const packageJson = JSON.parse(readFileSync(packageFile, { encoding: "utf-8" }).toString());
84
- if (!packageJson || !packageJson.name || !(packageJson.name + "").endsWith(`/${execDir}`)) {
85
- console.error(`工程 package.json/name 属性设置错误,应该跟目录名保持一致,请先调整`.red);
86
- process.exit(1);
87
- }
88
- envConfig.page = execDirWithPackage;
89
- const port = +envs[p];
90
- if (port) envConfig.port = port;
91
- envConfig.deployTo = (envs[t] || "").replace(/(?:^https?:\/\/|\/*$)/gi, "").replace(/^(.)/, "https://$1");
92
- envConfig.deployUser = envs[u];
93
- envConfig.deployKey = envs[k];
94
- if (mode === "wellknown") {
95
- const wellknownDir = join(process.cwd(), ".well-known");
96
- if (!existsSync(wellknownDir)) {
97
- console.error(`没有找到 .well-known 目录,它应该跟项目 package.json 文件在一个目录下`.red);
98
- process.exit(1);
99
- }
100
- if (!statSync(wellknownDir).isDirectory()) {
101
- console.error(`.well-known 应该是一个目录`.red);
102
- process.exit(1);
103
- }
104
- const files = readdirSync(wellknownDir);
105
- if (files.length === 0) {
106
- console.error(`.well-known 不能是一个空目录`.red);
107
- process.exit(1);
108
- }
109
- if (!envConfig.deployTo) {
110
- console.error(`缺少 ${t.bgRed} 设置,请在 .env.${mode} 中配置`.red);
111
- process.exit(1);
112
- }
113
- if (!envConfig.deployUser || !envConfig.deployKey) {
114
- console.error(`缺少 ${u.bgRed} / ${k.bgRed} 设置,请在 .env.local 配置`.red);
115
- process.exit(1);
116
- }
117
- envConfig.wellKnownDir = wellknownDir;
118
- return envConfig;
119
- }
120
- if (mode !== "build" && envConfig.command === "build") {
121
- if (!envConfig.deployTo) {
122
- console.error(`缺少 ${t.bgRed} 设置,请在 .env.${mode} 中配置`.red);
123
- process.exit(1);
124
- }
125
- if (!envConfig.deployUser || !envConfig.deployKey) {
126
- console.error(`缺少 ${u.bgRed} / ${k.bgRed} 设置,请在 .env.local 配置`.red);
127
- process.exit(1);
128
- }
129
- envConfig.sentryAuthToken = envs[s];
130
- if (!envConfig.sentryAuthToken) {
131
- if (requireSentryToken) {
132
- console.error(`缺少 ${s.red} 设置,请在 .env.local 配置`.red);
133
- process.exit(1);
134
- } else if (!ignoreSentryToken) {
135
- console.warn(`尚未设置 ${s.red},推送 sourcemap 到 sentry 的功能将无效`);
136
- }
137
- }
138
- if (ignoreSentryToken) {
139
- envConfig.sentryAuthToken = "";
140
- }
141
- }
142
- return envConfig;
78
+ const envs = loadEnv(mode, process.cwd(), "SY_");
79
+ const envConfig = {
80
+ command,
81
+ stamp: getNowTime(),
82
+ page: "",
83
+ mode: "",
84
+ deployUser: "",
85
+ deployKey: "",
86
+ viteEnvs: envs
87
+ };
88
+ envConfig.mode = mode || "preview";
89
+ const t = `SY_DEPLOY_TO`;
90
+ const s = `SY_SENTRY_AUTH_TOKEN`;
91
+ const u = `SY_DEPLOY_USER`;
92
+ const k = `SY_DEPLOY_KEY`;
93
+ const p = `SY_SERVER_PORT`;
94
+ const paths = process.cwd().replace(/\\/g, "/").split("/");
95
+ const execDirWithPackage = paths.slice(-2).join("/");
96
+ const execDir = paths.slice(-1)[0];
97
+ const packageFile = join(process.cwd(), "./package.json");
98
+ if (!existsSync(packageFile)) {
99
+ console.error("执行代码有误,没有找到 package.json".red);
100
+ process.exit(1);
101
+ }
102
+ const packageJson = JSON.parse(readFileSync(packageFile, { encoding: "utf-8" }).toString());
103
+ if (!packageJson || !packageJson.name || !(packageJson.name + "").endsWith(`/${execDir}`)) {
104
+ console.error(`工程 package.json/name 属性设置错误,应该跟目录名保持一致,请先调整`.red);
105
+ process.exit(1);
106
+ }
107
+ envConfig.page = execDirWithPackage;
108
+ const port = +envs[p];
109
+ if (port) envConfig.port = port;
110
+ envConfig.deployTo = (envs[t] || "").replace(/(?:^https?:\/\/|\/*$)/gi, "").replace(/^(.)/, "https://$1");
111
+ envConfig.deployUser = envs[u];
112
+ envConfig.deployKey = envs[k];
113
+ if (mode === "wellknown") {
114
+ const wellknownDir = join(process.cwd(), ".well-known");
115
+ if (!existsSync(wellknownDir)) {
116
+ console.error(`没有找到 .well-known 目录,它应该跟项目 package.json 文件在一个目录下`.red);
117
+ process.exit(1);
118
+ }
119
+ if (!statSync(wellknownDir).isDirectory()) {
120
+ console.error(`.well-known 应该是一个目录`.red);
121
+ process.exit(1);
122
+ }
123
+ if (readdirSync(wellknownDir).length === 0) {
124
+ console.error(`.well-known 不能是一个空目录`.red);
125
+ process.exit(1);
126
+ }
127
+ if (!envConfig.deployTo) {
128
+ console.error(`缺少 ${t.bgRed} 设置,请在 .env.${mode} 中配置`.red);
129
+ process.exit(1);
130
+ }
131
+ if (!envConfig.deployUser || !envConfig.deployKey) {
132
+ console.error(`缺少 ${u.bgRed} / ${k.bgRed} 设置,请在 .env.local 配置`.red);
133
+ process.exit(1);
134
+ }
135
+ envConfig.wellKnownDir = wellknownDir;
136
+ return envConfig;
137
+ }
138
+ if (mode !== "build" && envConfig.command === "build") {
139
+ if (!envConfig.deployTo) {
140
+ console.error(`缺少 ${t.bgRed} 设置,请在 .env.${mode} 中配置`.red);
141
+ process.exit(1);
142
+ }
143
+ if (!envConfig.deployUser || !envConfig.deployKey) {
144
+ console.error(`缺少 ${u.bgRed} / ${k.bgRed} 设置,请在 .env.local 配置`.red);
145
+ process.exit(1);
146
+ }
147
+ envConfig.sentryAuthToken = envs[s];
148
+ if (!envConfig.sentryAuthToken) {
149
+ if (requireSentryToken) {
150
+ console.error(`缺少 ${s.red} 设置,请在 .env.local 配置`.red);
151
+ process.exit(1);
152
+ } else if (!ignoreSentryToken) console.warn(`尚未设置 ${s.red},推送 sourcemap 到 sentry 的功能将无效`);
153
+ }
154
+ if (ignoreSentryToken) envConfig.sentryAuthToken = "";
155
+ }
156
+ return envConfig;
143
157
  }
144
158
  function transformEnvs(envs) {
145
- return Object.entries(envs).reduce(
146
- function(result, [key, value]) {
147
- result[key] = JSON.stringify(value);
148
- return result;
149
- },
150
- {}
151
- );
159
+ return Object.entries(envs).reduce(function(result, [key, value]) {
160
+ result[key] = JSON.stringify(value);
161
+ return result;
162
+ }, {});
152
163
  }
164
+ //#endregion
165
+ //#region src/inject.ts
166
+ /**
167
+ * 给模板文件注入数据
168
+ */
153
169
  function htmlInjectPlugin(data) {
154
- return {
155
- name: "html-inject-plugin",
156
- transformIndexHtml: {
157
- order: "pre",
158
- handler: function(html) {
159
- return html.replace(/%\s*(.*?)\s*%/g, (match, p1) => data[p1] ?? match).replace(/`{{\s*(.*?)\s*}}`/g, (match, p1) => data[p1] ?? match).replace(/[\r\n]{2,}/g, "\n").replace(/(?:^[\s\r\n]*|[\s\r\n]*$)/g, "");
160
- }
161
- }
162
- };
170
+ return {
171
+ name: "html-inject-plugin",
172
+ transformIndexHtml: {
173
+ order: "pre",
174
+ handler: function(html) {
175
+ return html.replace(/%\s*(.*?)\s*%/g, (match, p1) => data[p1] ?? match).replace(/`{{\s*(.*?)\s*}}`/g, (match, p1) => data[p1] ?? match).replace(/[\r\n]{2,}/g, "\n").replace(/(?:^[\s\r\n]*|[\s\r\n]*$)/g, "");
176
+ }
177
+ }
178
+ };
163
179
  }
180
+ //#endregion
181
+ //#region src/vite.page.ts
182
+ /**
183
+ * 导出一个动态的配置工厂函数
184
+ */
164
185
  function definePageBuildConfig(option) {
165
- const {
166
- preset = {},
167
- plugins = [],
168
- build = {},
169
- resolve = {},
170
- server = {},
171
- sentry = {},
172
- envTransformer,
173
- base,
174
- ...optionReset
175
- } = option || {};
176
- const { alias, ...resolveReset } = resolve;
177
- if (server.port) {
178
- console.warn(`ServerPort 不允许直接修改,请使用环境变量 ${EnvPrefix}SERVER_PORT 设置`);
179
- delete server.port;
180
- }
181
- return async function({ command, mode }) {
182
- const envs = getBuildEnv(command, mode, sentry.required, sentry.ignore);
183
- const justBuild = mode === "build";
184
- const gitInfo = justBuild ? null : await getCommitInfo(command, mode, envs.page, envs.deployTo || "");
185
- const isProductMode = mode === "production" || mode === "prod" || mode === "prd";
186
- if (mode === "wellknown" && envs.wellKnownDir && envs.deployTo) {
187
- const result = await finderDeploy({
188
- preview: false,
189
- deployTo: envs.deployTo.replace(/\/$/, "") + "/.well-known",
190
- dist: envs.wellKnownDir,
191
- user: envs.deployUser,
192
- key: envs.deployKey
193
- }).catch((e) => e instanceof Error ? e : typeof e === "string" ? new Error(e) : new Error(e + ""));
194
- if (result instanceof Error) {
195
- console.log("部署 .well-known 失败".bgRed, result.message);
196
- } else {
197
- console.log("部署 .well-known 成功".bgGreen, (result || "").green);
198
- }
199
- process.exit(0);
200
- }
201
- if (envTransformer) {
202
- envs.viteEnvs = await envTransformer(envs.viteEnvs, command, mode);
203
- }
204
- const trunkMap = {
205
- "naive-ui": "naive-ui",
206
- html2canvas: "html2canvas",
207
- swiper: "swiper",
208
- ...preset.manualChunks
209
- };
210
- const ignoreSideEffects = ["thinkingdata", "@esotericsoftware/spine", ...preset.badPackages || []];
211
- const baseValue = typeof base === "function" ? base(mode, envs.viteEnvs) : typeof base === "object" && base ? base[mode] : typeof base === "string" ? base : "./";
212
- if (baseValue === void 0 && mode !== "development") {
213
- console.warn(`base 参数在模式(${mode})下未设置内容`.red);
214
- process.exit(1);
215
- }
216
- return {
217
- base: baseValue || "./",
218
- build: {
219
- emptyOutDir: true,
220
- outDir: join(process.cwd(), "./dist"),
221
- assetsDir: "assets",
222
- reportCompressedSize: false,
223
- sourcemap: command === "build" && !!envs.sentryAuthToken ? "hidden" : false,
224
- ...build,
225
- rollupOptions: {
226
- treeshake: {
227
- moduleSideEffects: function(id) {
228
- return !ignoreSideEffects.some((k) => id.includes(k));
229
- }
230
- },
231
- ...build.rollupOptions,
232
- output: {
233
- manualChunks: function(id) {
234
- const k = Object.keys(trunkMap).find((k2) => id.includes(k2));
235
- if (k) return trunkMap[k];
236
- },
237
- ...build.rollupOptions?.output
238
- }
239
- }
240
- },
241
- plugins: [
242
- preset.ignoreVuePlugin ? null : vue(),
243
- preset.ignorePolyfill ? null : legacy(
244
- preset.polyfill ?? {
245
- targets: ["defaults", "chrome >= 52", "> 0.1%", "last 5 versions and not dead"],
246
- // https://github.com/vitejs/vite/blob/main/packages/plugin-legacy/src/index.ts#L170
247
- // https://unpkg.com/browse/core-js@3.41.0/
248
- additionalLegacyPolyfills: [
249
- "regenerator-runtime/runtime",
250
- "core-js/es/global-this",
251
- "core-js/es/array/flat",
252
- "core-js/es/array/flat-map",
253
- "core-js/es/promise/all-settled",
254
- "core-js/es/promise/any",
255
- "core-js/es/symbol/iterator"
256
- ],
257
- additionalModernPolyfills: [
258
- "core-js/es/global-this",
259
- "core-js/es/array/flat",
260
- "core-js/es/array/flat-map",
261
- "core-js/es/promise/all-settled",
262
- "core-js/es/promise/any",
263
- "core-js/es/symbol/iterator"
264
- ]
265
- }
266
- ),
267
- htmlInjectPlugin({
268
- BUILD_TIME: envs.stamp,
269
- BUILD_MODE: envs.mode,
270
- BUILD_VERSION: gitInfo?.hash || "",
271
- ...envs.viteEnvs
272
- }),
273
- ...plugins,
274
- command === "build" && envs.deployTo && !justBuild && gitInfo ? viteDeployPlugin({
275
- deployTo: envs.deployTo,
276
- // 忽略 js sourcemap 文件
277
- ignoreFiles: ["*.js.map", ...option?.finder?.ignoreFiles || []],
278
- user: envs.deployUser,
279
- key: envs.deployKey,
280
- debug: option?.finder?.debug,
281
- preview: option?.finder?.preview ?? true,
282
- ignoreCache: option?.finder?.ignoreServerListCache,
283
- commitLogs: isProductMode && gitInfo.logs.length > 0 ? "\n" + gitInfo.logs.join("\n") : void 0,
284
- onBeforeDeploy: option?.finder?.beforeDeploy ? async function(dist) {
285
- await option?.finder?.beforeDeploy?.(dist, envs.viteEnvs);
286
- } : void 0,
287
- onFinished() {
288
- if (isProductMode) {
289
- createPageDeployTag(envs.page, envs.deployTo || "", envs.deployUser);
290
- }
291
- }
292
- }) : null,
293
- command === "build" && envs.sentryAuthToken && !justBuild ? sentryVitePlugin({
294
- authToken: envs.sentryAuthToken,
295
- org: sentry.org || "sentry",
296
- url: sentry.url || "https://sentry.seayoo.com",
297
- project: sentry.project || "gamer-fe",
298
- ...plugins
299
- }) : null,
300
- justBuild ? visualizer() : null
301
- ],
302
- define: transformEnvs({
303
- BUILD_TIME: envs.stamp,
304
- BUILD_MODE: envs.mode,
305
- ...envs.viteEnvs
306
- }),
307
- resolve: {
308
- alias: {
309
- "@": join(process.cwd(), "./src"),
310
- ...alias
311
- },
312
- extensions: [".mts", ".mjs", ".ts", ".js"],
313
- ...resolveReset
314
- },
315
- server: {
316
- open: true,
317
- port: envs.port,
318
- ...server
319
- },
320
- ...optionReset,
321
- // envPrefix 不允许覆盖
322
- envPrefix: EnvPrefix
323
- };
324
- };
186
+ const { preset = {}, plugins = [], build = {}, resolve = {}, server = {}, sentry = {}, envTransformer, base, ...optionReset } = option || {};
187
+ const { alias, ...resolveReset } = resolve;
188
+ if (server.port) {
189
+ console.warn(`ServerPort 不允许直接修改,请使用环境变量 SY_SERVER_PORT 设置`);
190
+ delete server.port;
191
+ }
192
+ return async function({ command, mode }) {
193
+ const envs = getBuildEnv(command, mode, sentry.required, sentry.ignore);
194
+ const justBuild = mode === "build";
195
+ const gitInfo = justBuild ? null : await getCommitInfo(command, mode, envs.page, envs.deployTo || "");
196
+ const isProductMode = mode === "production" || mode === "prod" || mode === "prd";
197
+ if (mode === "wellknown" && envs.wellKnownDir && envs.deployTo) {
198
+ const result = await finderDeploy({
199
+ preview: false,
200
+ deployTo: envs.deployTo.replace(/\/$/, "") + "/.well-known",
201
+ dist: envs.wellKnownDir,
202
+ user: envs.deployUser,
203
+ key: envs.deployKey
204
+ }).catch((e) => e instanceof Error ? e : typeof e === "string" ? new Error(e) : /* @__PURE__ */ new Error(e + ""));
205
+ if (result instanceof Error) console.log("部署 .well-known 失败".bgRed, result.message);
206
+ else console.log("部署 .well-known 成功".bgGreen, (result || "").green);
207
+ process.exit(0);
208
+ }
209
+ if (envTransformer) envs.viteEnvs = await envTransformer(envs.viteEnvs, command, mode);
210
+ const trunkMap = {
211
+ "naive-ui": "naive-ui",
212
+ html2canvas: "html2canvas",
213
+ swiper: "swiper",
214
+ ...preset.manualChunks
215
+ };
216
+ const ignoreSideEffects = [
217
+ "thinkingdata",
218
+ "@esotericsoftware/spine",
219
+ ...preset.badPackages || []
220
+ ];
221
+ const baseValue = typeof base === "function" ? base(mode, envs.viteEnvs) : typeof base === "object" && base ? base[mode] : typeof base === "string" ? base : "./";
222
+ if (baseValue === void 0 && mode !== "development") {
223
+ console.warn(`base 参数在模式(${mode})下未设置内容`.red);
224
+ process.exit(1);
225
+ }
226
+ return defineConfig({
227
+ base: baseValue || "./",
228
+ build: {
229
+ emptyOutDir: true,
230
+ outDir: join(process.cwd(), "./dist"),
231
+ assetsDir: "assets",
232
+ reportCompressedSize: false,
233
+ sourcemap: command === "build" && !!envs.sentryAuthToken ? "hidden" : false,
234
+ ...build,
235
+ rolldownOptions: {
236
+ treeshake: { moduleSideEffects: function(id) {
237
+ return !ignoreSideEffects.some((k) => id.includes(k));
238
+ } },
239
+ ...build.rolldownOptions,
240
+ output: {
241
+ manualChunks: function(id) {
242
+ const k = Object.keys(trunkMap).find((j) => id.includes(j));
243
+ if (k) return trunkMap[k];
244
+ },
245
+ ...build.rolldownOptions?.output
246
+ }
247
+ }
248
+ },
249
+ plugins: [
250
+ preset.ignoreVuePlugin ? null : vue(),
251
+ preset.ignorePolyfill ? null : legacy(preset.polyfill ?? {
252
+ targets: [
253
+ "defaults",
254
+ "chrome >= 52",
255
+ "> 0.1%",
256
+ "last 5 versions and not dead"
257
+ ],
258
+ additionalLegacyPolyfills: [
259
+ "regenerator-runtime/runtime",
260
+ "core-js/es/global-this",
261
+ "core-js/es/array/flat",
262
+ "core-js/es/array/flat-map",
263
+ "core-js/es/promise/all-settled",
264
+ "core-js/es/promise/any",
265
+ "core-js/es/symbol/iterator"
266
+ ],
267
+ additionalModernPolyfills: [
268
+ "core-js/es/global-this",
269
+ "core-js/es/array/flat",
270
+ "core-js/es/array/flat-map",
271
+ "core-js/es/promise/all-settled",
272
+ "core-js/es/promise/any",
273
+ "core-js/es/symbol/iterator"
274
+ ]
275
+ }),
276
+ htmlInjectPlugin({
277
+ BUILD_TIME: envs.stamp,
278
+ BUILD_MODE: envs.mode,
279
+ BUILD_VERSION: gitInfo?.hash || "",
280
+ ...envs.viteEnvs
281
+ }),
282
+ ...plugins,
283
+ command === "build" && envs.deployTo && !justBuild && gitInfo ? viteDeployPlugin({
284
+ deployTo: envs.deployTo,
285
+ ignoreFiles: ["*.js.map", ...option?.finder?.ignoreFiles || []],
286
+ user: envs.deployUser,
287
+ key: envs.deployKey,
288
+ debug: option?.finder?.debug,
289
+ preview: option?.finder?.preview ?? true,
290
+ ignoreCache: option?.finder?.ignoreServerListCache,
291
+ commitLogs: isProductMode && gitInfo.logs.length > 0 ? "\n" + gitInfo.logs.join("\n") : void 0,
292
+ onBeforeDeploy: option?.finder?.beforeDeploy ? async function(dist) {
293
+ await option?.finder?.beforeDeploy?.(dist, envs.viteEnvs);
294
+ } : void 0,
295
+ onFinished() {
296
+ if (isProductMode) createPageDeployTag(envs.page, envs.deployTo || "", envs.deployUser);
297
+ }
298
+ }) : null,
299
+ command === "build" && envs.sentryAuthToken && !justBuild ? sentryVitePlugin({
300
+ authToken: envs.sentryAuthToken,
301
+ org: sentry.org || "sentry",
302
+ url: sentry.url || "https://sentry.seayoo.com",
303
+ project: sentry.project || "gamer-fe",
304
+ ...plugins
305
+ }) : null,
306
+ justBuild ? visualizer() : null
307
+ ],
308
+ define: transformEnvs({
309
+ BUILD_TIME: envs.stamp,
310
+ BUILD_MODE: envs.mode,
311
+ ...envs.viteEnvs
312
+ }),
313
+ resolve: {
314
+ alias: {
315
+ "@": join(process.cwd(), "./src"),
316
+ ...alias
317
+ },
318
+ extensions: [
319
+ ".mts",
320
+ ".mjs",
321
+ ".ts",
322
+ ".js"
323
+ ],
324
+ ...resolveReset
325
+ },
326
+ server: {
327
+ open: true,
328
+ port: envs.port,
329
+ ...server
330
+ },
331
+ ...optionReset,
332
+ envPrefix: "SY_"
333
+ });
334
+ };
325
335
  }
326
- const vueEslintConfig = [
327
- {
328
- name: "app/files-to-lint",
329
- files: ["**/*.{ts,mts,tsx,vue,mjs}"]
330
- },
331
- {
332
- name: "app/files-to-ignore",
333
- ignores: ["*.mjs", "**/dist/**", "**/bin/**", "**/types/**", "**/dist-ssr/**", "**/coverage/**"]
334
- },
335
- pluginVue.configs["flat/essential"],
336
- vueTsConfigs.recommended,
337
- skipFormatting,
338
- {
339
- files: ["**/*.vue"],
340
- rules: {
341
- "vue/multi-word-component-names": "off"
342
- }
343
- }
344
- ];
345
- const importOrderRuleConfig = {
346
- groups: ["builtin", "external", "internal", "parent", "sibling", "index", "type"],
347
- pathGroups: [
348
- {
349
- pattern: "@/**",
350
- group: "internal"
351
- }
352
- ],
353
- distinctGroup: true,
354
- "newlines-between": "always",
355
- alphabetize: {
356
- order: "asc",
357
- caseInsensitive: true
358
- }
359
- };
360
- const importEslintConfig = [
361
- flatConfigs.recommended,
362
- {
363
- rules: {
364
- "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
365
- "import/no-unresolved": "off",
366
- "import/named": "off",
367
- "import/namespace": "off",
368
- "import/no-named-as-default": "off",
369
- "import/no-named-as-default-member": "off",
370
- "import/export": "error",
371
- "import/order": ["error", importOrderRuleConfig]
372
- }
373
- }
374
- ];
375
- function defineEslintConfig(...options) {
376
- return defineConfigWithVueTs(vueEslintConfig, importEslintConfig, options);
336
+ //#endregion
337
+ //#region src/oxlint.ts
338
+ function defineOxlintConfig(options) {
339
+ return defineConfig$1({
340
+ plugins: [
341
+ "typescript",
342
+ "import",
343
+ ...options?.plugins || ["vue"]
344
+ ],
345
+ categories: {
346
+ correctness: "error",
347
+ perf: "warn",
348
+ suspicious: "warn"
349
+ },
350
+ ignorePatterns: [
351
+ "**/dist/**",
352
+ "**/bin/**",
353
+ "**/types/**",
354
+ "**/coverage/**"
355
+ ],
356
+ rules: {
357
+ "vue/multi-word-component-names": "off",
358
+ "import/no-unresolved": "off",
359
+ ...options?.rules
360
+ },
361
+ env: options?.env || { browser: true },
362
+ overrides: options?.overrides,
363
+ globals: options?.globals
364
+ });
377
365
  }
378
- const stylelintConfig = {
379
- extends: ["stylelint-config-standard", "stylelint-config-recess-order"],
380
- overrides: [
381
- {
382
- files: ["**/*.vue", "**/*.html"],
383
- customSyntax: "postcss-html"
384
- }
385
- ],
386
- rules: {
387
- "selector-class-pattern": /^[a-z\d-_]+$/,
388
- "media-feature-range-notation": "prefix",
389
- "color-function-notation": "legacy",
390
- "color-function-alias-notation": "with-alpha",
391
- "alpha-value-notation": "number",
392
- "unit-no-unknown": [
393
- true,
394
- {
395
- ignoreUnits: ["rpx"]
396
- }
397
- ],
398
- "selector-pseudo-class-no-unknown": [
399
- true,
400
- {
401
- ignorePseudoClasses: ["deep", "global"]
402
- }
403
- ],
404
- "declaration-block-no-redundant-longhand-properties": [
405
- true,
406
- {
407
- ignoreShorthands: ["inset"]
408
- }
409
- ]
410
- }
411
- };
412
- export {
413
- EnvPrefix,
414
- defineAppBuildConfig,
415
- defineEslintConfig,
416
- defineLibBuildConfig,
417
- definePageBuildConfig,
418
- getBuildEnv,
419
- htmlInjectPlugin,
420
- importOrderRuleConfig,
421
- stylelintConfig,
422
- transformEnvs
423
- };
366
+ //#endregion
367
+ //#region src/oxfmt.ts
368
+ /**
369
+ * 获取 oxfmt 配置
370
+ *
371
+ * https://oxc.rs/docs/guide/usage/formatter/config-file-reference.html
372
+ */
373
+ function defineOxfmtConfig() {
374
+ return defineConfig$2({
375
+ sortImports: {
376
+ newlinesBetween: false,
377
+ ignoreCase: true,
378
+ groups: [
379
+ "builtin",
380
+ "external",
381
+ ["internal", "subpath"],
382
+ { newlinesBetween: true },
383
+ "parent",
384
+ "sibling",
385
+ "index",
386
+ { newlinesBetween: true },
387
+ ["style", "side_effect_style"],
388
+ { newlinesBetween: true },
389
+ "type",
390
+ { newlinesBetween: true },
391
+ "unknown"
392
+ ]
393
+ },
394
+ ignorePatterns: [
395
+ "**/dist/**",
396
+ "**/bin/**",
397
+ "**/types/**",
398
+ "**/coverage/**"
399
+ ],
400
+ semi: true,
401
+ useTabs: false,
402
+ printWidth: 120,
403
+ singleQuote: false,
404
+ trailingComma: "all",
405
+ bracketSpacing: true,
406
+ endOfLine: "lf"
407
+ });
408
+ }
409
+ //#endregion
410
+ export { EnvPrefix, defineAppBuildConfig, defineLibBuildConfig, defineOxfmtConfig, defineOxlintConfig, definePageBuildConfig, getBuildEnv, htmlInjectPlugin, transformEnvs };