@seayoo-web/scripts 2.0.12 → 2.1.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/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import vue from "@vitejs/plugin-vue";
3
+ import { visualizer } from "rollup-plugin-visualizer";
3
4
  import { viteDeployPlugin } from "@seayoo-web/finder";
4
5
  import { sentryVitePlugin } from "@sentry/vite-plugin";
5
6
  import legacy from "@vitejs/plugin-legacy";
@@ -25,7 +26,7 @@ function defineAppBuildConfig(option) {
25
26
  sourcemap: false,
26
27
  ...build
27
28
  },
28
- plugins: [vue(), ...plugins],
29
+ plugins: [vue(), (option == null ? void 0 : option.visualizer) ? visualizer() : null, ...plugins],
29
30
  resolve: {
30
31
  alias: {
31
32
  "@": join(process.cwd(), "./src"),
@@ -135,6 +136,7 @@ function definePageBuildConfig(option) {
135
136
  const {
136
137
  onlyBuild,
137
138
  manualChunks,
139
+ badPackages = [],
138
140
  plugins = [],
139
141
  define = {},
140
142
  build = {},
@@ -153,7 +155,6 @@ function definePageBuildConfig(option) {
153
155
  const trunkMap = {
154
156
  "naive-ui": "naive-ui",
155
157
  html2canvas: "html2canvas",
156
- thinkingdata: "thinkingdata",
157
158
  ...manualChunks
158
159
  };
159
160
  const trunkKeys = Object.keys(trunkMap);
@@ -161,6 +162,7 @@ function definePageBuildConfig(option) {
161
162
  const k = trunkKeys.find((k2) => id.includes(k2));
162
163
  if (k) return trunkMap[k];
163
164
  };
165
+ const ignoreSideEffects = ["thinkingdata", "@esotericsoftware/spine", ...badPackages];
164
166
  return {
165
167
  base: "./",
166
168
  build: {
@@ -171,11 +173,16 @@ function definePageBuildConfig(option) {
171
173
  sourcemap: command === "build" && !!envs.sentryAuthToken ? "hidden" : false,
172
174
  ...build,
173
175
  rollupOptions: {
176
+ treeshake: {
177
+ moduleSideEffects: function(id) {
178
+ return !ignoreSideEffects.some((k) => id.includes(k));
179
+ }
180
+ },
181
+ ...build.rollupOptions,
174
182
  output: {
175
183
  manualChunks: trunkFn,
176
184
  ...(_a = build.rollupOptions) == null ? void 0 : _a.output
177
- },
178
- ...build.rollupOptions
185
+ }
179
186
  }
180
187
  },
181
188
  plugins: [
@@ -229,7 +236,8 @@ function definePageBuildConfig(option) {
229
236
  org: "sentry",
230
237
  url: sentry.url || "https://sentry.seayoo.com/",
231
238
  project: sentry.project || "gamer-fe"
232
- }) : null
239
+ }) : null,
240
+ justBuild ? visualizer() : null
233
241
  ],
234
242
  define: transformEnvs({
235
243
  BUILD_TIME: envs.stamp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/scripts",
3
- "version": "2.0.12",
3
+ "version": "2.1.1",
4
4
  "description": "scripts for seayoo web repos",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -47,6 +47,7 @@
47
47
  "jiti": "^2.4.2",
48
48
  "ora": "^8.2.0",
49
49
  "postcss-html": "^1.8.0",
50
+ "rollup-plugin-visualizer": "^5.14.0",
50
51
  "terser": "^5.39.0",
51
52
  "vite-plugin-stylelint": "^6.0.0",
52
53
  "vite-plugin-vue-devtools": "^7.7.5",
@@ -2,4 +2,6 @@ import type { UserConfig } from "vite";
2
2
  /**
3
3
  * 导出一个动态的配置工厂函数
4
4
  */
5
- export declare function defineAppBuildConfig(option?: UserConfig): UserConfig;
5
+ export declare function defineAppBuildConfig(option?: UserConfig & {
6
+ visualizer?: boolean;
7
+ }): UserConfig;
@@ -1,4 +1,4 @@
1
- import { type UserConfig } from "vite";
1
+ import type { UserConfig } from "vite";
2
2
  interface LibBuildOption {
3
3
  /** 输出目录,默认为 "dist" */
4
4
  outDir?: string;
@@ -10,13 +10,19 @@ interface ExternalConfig {
10
10
  /**
11
11
  * 手工指定 trunk 合并策略,Record<key, chunk>,即 id.include(key) 则打到 trunk 中
12
12
  *
13
- * 默认 {`naive-ui`, `html2canvas`, `thinkingdata`}
13
+ * 默认 {`naive-ui`, `html2canvas`}
14
14
  *
15
15
  * 设置的值会跟默认值进行合并。
16
16
  *
17
17
  * 也可以手工设定 `build.rollupOptions.output.manualChunks` 来自定义
18
18
  */
19
19
  manualChunks?: Record<string, string>;
20
+ /**
21
+ * 指定哪些不够友好的包,这些包的 iife 或修改全局 windows 变量的行为导致默认 tree-shaking 策略失效
22
+ *
23
+ * 从而这些包被误打入最终的产物中,无谓增加了包的体积。默认 `thinkingdata` 和 `@esotericsoftware`
24
+ */
25
+ badPackages?: string[];
20
26
  }
21
27
  /**
22
28
  * 导出一个动态的配置工厂函数