@seayoo-web/scripts 2.1.0 → 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
@@ -136,6 +136,7 @@ function definePageBuildConfig(option) {
136
136
  const {
137
137
  onlyBuild,
138
138
  manualChunks,
139
+ badPackages = [],
139
140
  plugins = [],
140
141
  define = {},
141
142
  build = {},
@@ -154,7 +155,6 @@ function definePageBuildConfig(option) {
154
155
  const trunkMap = {
155
156
  "naive-ui": "naive-ui",
156
157
  html2canvas: "html2canvas",
157
- thinkingdata: "thinkingdata",
158
158
  ...manualChunks
159
159
  };
160
160
  const trunkKeys = Object.keys(trunkMap);
@@ -162,6 +162,7 @@ function definePageBuildConfig(option) {
162
162
  const k = trunkKeys.find((k2) => id.includes(k2));
163
163
  if (k) return trunkMap[k];
164
164
  };
165
+ const ignoreSideEffects = ["thinkingdata", "@esotericsoftware/spine", ...badPackages];
165
166
  return {
166
167
  base: "./",
167
168
  build: {
@@ -172,11 +173,16 @@ function definePageBuildConfig(option) {
172
173
  sourcemap: command === "build" && !!envs.sentryAuthToken ? "hidden" : false,
173
174
  ...build,
174
175
  rollupOptions: {
176
+ treeshake: {
177
+ moduleSideEffects: function(id) {
178
+ return !ignoreSideEffects.some((k) => id.includes(k));
179
+ }
180
+ },
181
+ ...build.rollupOptions,
175
182
  output: {
176
183
  manualChunks: trunkFn,
177
184
  ...(_a = build.rollupOptions) == null ? void 0 : _a.output
178
- },
179
- ...build.rollupOptions
185
+ }
180
186
  }
181
187
  },
182
188
  plugins: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/scripts",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "scripts for seayoo web repos",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -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
  * 导出一个动态的配置工厂函数