@seayoo-web/scripts 2.9.0 → 3.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
@@ -157,24 +157,21 @@ function htmlInjectPlugin(data) {
157
157
  name: "html-inject-plugin",
158
158
  transformIndexHtml: {
159
159
  order: "pre",
160
- handler: (html) => 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
+ handler: function(html) {
161
+ 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, "");
162
+ }
161
163
  }
162
164
  };
163
165
  }
164
166
  function definePageBuildConfig(option) {
165
167
  const {
166
- notVuePage,
167
- noPolyfill,
168
- requireSentryToken,
169
- ignoreSentryToken,
170
- manualChunks,
171
- badPackages = [],
168
+ preset = {},
172
169
  plugins = [],
173
170
  build = {},
174
171
  resolve = {},
175
172
  server = {},
176
173
  sentry = {},
177
- envTransform,
174
+ envTransformer,
178
175
  base,
179
176
  ...optionReset
180
177
  } = option || {};
@@ -184,7 +181,7 @@ function definePageBuildConfig(option) {
184
181
  delete server.port;
185
182
  }
186
183
  return async function({ command, mode }) {
187
- const envs = getBuildEnv(command, mode, requireSentryToken, ignoreSentryToken);
184
+ const envs = getBuildEnv(command, mode, sentry.required, sentry.ignore);
188
185
  const justBuild = mode === "build";
189
186
  const gitInfo = justBuild ? null : await getCommitInfo(command, mode, envs.page, envs.deployTo || "");
190
187
  const isProductMode = mode === "production" || mode === "prod" || mode === "prd";
@@ -203,22 +200,17 @@ function definePageBuildConfig(option) {
203
200
  }
204
201
  process.exit(0);
205
202
  }
206
- if (envTransform) {
207
- envs.viteEnvs = await envTransform(envs.viteEnvs, command, mode);
203
+ if (envTransformer) {
204
+ envs.viteEnvs = await envTransformer(envs.viteEnvs, command, mode);
208
205
  }
209
206
  const trunkMap = {
210
207
  "naive-ui": "naive-ui",
211
208
  html2canvas: "html2canvas",
212
209
  swiper: "swiper",
213
- ...manualChunks
214
- };
215
- const trunkKeys = Object.keys(trunkMap);
216
- const trunkFn = function(id) {
217
- const k = trunkKeys.find((k2) => id.includes(k2));
218
- if (k) return trunkMap[k];
210
+ ...preset.manualChunks
219
211
  };
220
- const ignoreSideEffects = ["thinkingdata", "@esotericsoftware/spine", ...badPackages];
221
- const baseValue = typeof base === "function" ? base(mode, envs.viteEnvs) || "./" : typeof base === "object" && base ? base[mode] : typeof base === "string" ? base : "./";
212
+ const ignoreSideEffects = ["thinkingdata", "@esotericsoftware/spine", ...preset.badPackages || []];
213
+ const baseValue = typeof base === "function" ? base(mode, envs.viteEnvs) : typeof base === "object" && base ? base[mode] : typeof base === "string" ? base : "./";
222
214
  if (baseValue === void 0 && mode !== "development") {
223
215
  console.warn(`base 参数在模式(${mode})下未设置内容`.red);
224
216
  process.exit(1);
@@ -240,15 +232,17 @@ function definePageBuildConfig(option) {
240
232
  },
241
233
  ...build.rollupOptions,
242
234
  output: {
243
- manualChunks: trunkFn,
235
+ manualChunks: function(id) {
236
+ const k = Object.keys(trunkMap).find((k2) => id.includes(k2));
237
+ if (k) return trunkMap[k];
238
+ },
244
239
  ...build.rollupOptions?.output
245
240
  }
246
241
  }
247
242
  },
248
243
  plugins: [
249
- notVuePage ? null : vue(),
250
- // notVuePage ? null : vueDevTools(),
251
- noPolyfill ? null : legacy({
244
+ preset.ignoreVuePlugin ? null : vue(),
245
+ preset.ignorePolyfill ? null : legacy({
252
246
  targets: ["defaults", "> 0.1%", "last 5 versions and not dead"],
253
247
  // https://github.com/vitejs/vite/blob/main/packages/plugin-legacy/src/index.ts#L170
254
248
  // https://unpkg.com/browse/core-js@3.41.0/
@@ -285,6 +279,9 @@ function definePageBuildConfig(option) {
285
279
  debug: envs.deployDebug,
286
280
  preview: option?.finder?.preview ?? true,
287
281
  commitLogs: isProductMode && gitInfo.logs.length > 0 ? "\n" + gitInfo.logs.join("\n") : void 0,
282
+ onBeforeDeploy: option?.finder?.beforeDeploy ? async function(dist) {
283
+ await option?.finder?.beforeDeploy?.(dist, envs.viteEnvs);
284
+ } : void 0,
288
285
  onFinished() {
289
286
  if (isProductMode) {
290
287
  createPageDeployTag(envs.page, envs.deployTo || "", envs.deployUser);
@@ -294,7 +291,7 @@ function definePageBuildConfig(option) {
294
291
  command === "build" && envs.sentryAuthToken && !justBuild ? sentryVitePlugin({
295
292
  authToken: envs.sentryAuthToken,
296
293
  org: sentry.org || "sentry",
297
- url: sentry.url || "https://sentry.seayoo.com/",
294
+ url: sentry.url || "https://sentry.seayoo.com",
298
295
  project: sentry.project || "gamer-fe"
299
296
  }) : null,
300
297
  justBuild ? visualizer() : null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/scripts",
3
- "version": "2.9.0",
3
+ "version": "3.0.0",
4
4
  "description": "scripts for seayoo web repos",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -33,11 +33,11 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@sentry/vite-plugin": "^3.3.1",
37
- "@vitejs/plugin-legacy": "^7.0.0",
38
- "@vitejs/plugin-vue": "^6.0.0",
36
+ "@sentry/vite-plugin": "^4.0.2",
37
+ "@vitejs/plugin-legacy": "^7.1.0",
38
+ "@vitejs/plugin-vue": "^6.0.1",
39
39
  "@vue/eslint-config-prettier": "^10.2.0",
40
- "@vue/eslint-config-typescript": "^14.5.0",
40
+ "@vue/eslint-config-typescript": "^14.6.0",
41
41
  "chokidar": "^4.0.3",
42
42
  "colors": "^1.4.0",
43
43
  "commander": "^13.1.0",
@@ -50,10 +50,10 @@
50
50
  "ora": "^8.2.0",
51
51
  "postcss-html": "^1.8.0",
52
52
  "rollup-plugin-visualizer": "^6.0.3",
53
+ "stylelint-order": "^7.0.0",
53
54
  "terser": "^5.43.1",
54
55
  "vite-plugin-stylelint": "^6.0.2",
55
- "stylelint-order": "^7.0.0",
56
- "@seayoo-web/finder": "^2.1.1"
56
+ "@seayoo-web/finder": "^2.2.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/fs-extra": "^11.0.4",
@@ -4,7 +4,7 @@
4
4
  export declare function htmlInjectPlugin(data: Record<string, string>): {
5
5
  name: string;
6
6
  transformIndexHtml: {
7
- order: string;
7
+ order: "pre";
8
8
  handler: (html: string) => string;
9
9
  };
10
10
  };
@@ -1,21 +1,55 @@
1
1
  import type { UserConfig, UserConfigFnPromise } from "vite";
2
2
  interface ExternalConfig {
3
- /** 设置base路径,支持配置多组 base,以 mode 为key */
4
- base?: string | Record<string, string> | ((mode: string, env: Record<string, string>) => string);
5
- /** 是否不使用 vue */
6
- notVuePage?: boolean;
7
- /** 是否不加载 polyfill */
8
- noPolyfill?: boolean;
3
+ /**
4
+ * 动态修改环境变量
5
+ */
6
+ envTransformer?: (envs: Record<string, string>, command: "build" | "serve", mode: string) => Promise<Record<string, string>> | Record<string, string>;
7
+ /**
8
+ * 设置base路径,支持配置多组 base(以 mode 为 key) 或自定义函数返回 base
9
+ */
10
+ base?: string | Record<string, string> | ((mode: string, envs: Record<string, string>) => string);
11
+ /**
12
+ * 功能预设配置
13
+ */
14
+ preset?: {
15
+ /**
16
+ * 忽略 vue 插件
17
+ */
18
+ ignoreVuePlugin?: boolean;
19
+ /**
20
+ * 是否忽略 polyfill
21
+ */
22
+ ignorePolyfill?: boolean;
23
+ /**
24
+ * 指定哪些不够友好的包,这些包的 iife 或修改全局 windows 变量的行为导致默认 tree-shaking 策略失效
25
+ *
26
+ * 从而这些包被误打入最终的产物中,无谓增加了包的体积。默认 `thinkingdata` 和 `@esotericsoftware/spine`
27
+ */
28
+ badPackages?: string[];
29
+ /**
30
+ * 手工指定 trunk 合并策略,Record<key, chunk>,即 id.include(key) 则打到 trunk 中
31
+ *
32
+ * 默认 {`naive-ui`, `html2canvas`, `swiper`}
33
+ *
34
+ * 设置的值会跟默认值进行合并。
35
+ *
36
+ * 也可以手工设定 `build.rollupOptions.output.manualChunks` 来自定义
37
+ */
38
+ manualChunks?: Record<string, string>;
39
+ };
9
40
  /** sentry 配置 */
10
41
  sentry?: {
42
+ /** 默认 `gamer-fe` */
11
43
  project?: string;
44
+ /** 默认 `https://sentry.seayoo.com` */
12
45
  url?: string;
46
+ /** 默认 `sentry` */
13
47
  org?: string;
48
+ /** 是否强制要求提供 sentryToken,优先级高于 ignore */
49
+ required?: boolean;
50
+ /** 是否忽略 sentryToken 设置 */
51
+ ignore?: boolean;
14
52
  };
15
- /** 是否强制要求提供 sentryToken */
16
- requireSentryToken?: boolean;
17
- /** 是否忽略 sentryToken 设置 */
18
- ignoreSentryToken?: boolean;
19
53
  /** finder 配置 */
20
54
  finder?: {
21
55
  /**
@@ -28,27 +62,11 @@ interface ExternalConfig {
28
62
  * 匹配时仅针对单一目录和文件名进行检查,不跨目录检查
29
63
  */
30
64
  ignoreFiles?: string[];
65
+ /**
66
+ * 在部署文件前调用,用以调整产物文件
67
+ */
68
+ beforeDeploy?: (distDir: string, envs: Record<string, string>) => unknown;
31
69
  };
32
- /**
33
- * 手工指定 trunk 合并策略,Record<key, chunk>,即 id.include(key) 则打到 trunk 中
34
- *
35
- * 默认 {`naive-ui`, `html2canvas`, `swiper`}
36
- *
37
- * 设置的值会跟默认值进行合并。
38
- *
39
- * 也可以手工设定 `build.rollupOptions.output.manualChunks` 来自定义
40
- */
41
- manualChunks?: Record<string, string>;
42
- /**
43
- * 指定哪些不够友好的包,这些包的 iife 或修改全局 windows 变量的行为导致默认 tree-shaking 策略失效
44
- *
45
- * 从而这些包被误打入最终的产物中,无谓增加了包的体积。默认 `thinkingdata` 和 `@esotericsoftware/spine`
46
- */
47
- badPackages?: string[];
48
- /**
49
- * 动态修改环境变量
50
- */
51
- envTransform?: (env: Record<string, string>, command: "build" | "serve", mode: string) => Promise<Record<string, string>> | Record<string, string>;
52
70
  }
53
71
  /**
54
72
  * 导出一个动态的配置工厂函数