@seayoo-web/scripts 2.0.4 → 2.0.6

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
@@ -55,7 +55,7 @@ function defineLibBuildConfig(option) {
55
55
  };
56
56
  }
57
57
  const EnvPrefix = "SY_";
58
- function getBuildEnv(command, mode) {
58
+ function getBuildEnv(command, mode, onlyBuild) {
59
59
  const envs = loadEnv(mode, process.cwd(), EnvPrefix);
60
60
  const envConfig = {
61
61
  command,
@@ -86,6 +86,9 @@ function getBuildEnv(command, mode) {
86
86
  process.exit(1);
87
87
  }
88
88
  envConfig.page = execDirWithPackage;
89
+ if (onlyBuild) {
90
+ return envConfig;
91
+ }
89
92
  if (envConfig.command === "build") {
90
93
  if (process.env.NODE_ENV !== "production") {
91
94
  console.error("部署时需要设置 NODE_ENV 为 production,请检查环境变量设置".red);
@@ -130,6 +133,8 @@ function htmlInjectPlugin(data) {
130
133
  }
131
134
  function definePageBuildConfig(option) {
132
135
  const {
136
+ onlyBuild,
137
+ manualChunks,
133
138
  plugins = [],
134
139
  define = {},
135
140
  build = {},
@@ -140,9 +145,23 @@ function definePageBuildConfig(option) {
140
145
  } = option || {};
141
146
  const { alias, ...resolveReset } = resolve;
142
147
  return async function({ command, mode }) {
143
- const envs = getBuildEnv(command, mode);
144
- const gitInfo = await getCommitInfo(command, mode, envs.page, envs.deployTo || "");
148
+ var _a;
149
+ const envs = getBuildEnv(command, mode, onlyBuild);
150
+ const gitInfo = onlyBuild ? null : await getCommitInfo(command, mode, envs.page, envs.deployTo || "");
145
151
  const isProductMode = mode === "production" || mode === "prod";
152
+ const trunkMap = {
153
+ "naive-ui": "naive-ui",
154
+ html2canvas: "html2canvas",
155
+ thinkingdata: "thinkingdata",
156
+ vue: "vue",
157
+ node_modules: "vendor",
158
+ ...manualChunks
159
+ };
160
+ const trunkKeys = Object.keys(trunkMap).sort((a, b) => a === "node_modules" ? 1 : b === "node_modules" ? -1 : 0);
161
+ const trunkFn = function(id) {
162
+ const k = trunkKeys.find((k2) => id.includes(k2));
163
+ if (k) return trunkMap[k];
164
+ };
146
165
  return {
147
166
  base: "./",
148
167
  build: {
@@ -151,7 +170,14 @@ function definePageBuildConfig(option) {
151
170
  assetsDir: "assets",
152
171
  reportCompressedSize: false,
153
172
  sourcemap: command === "build" && !!envs.sentryAuthToken,
154
- ...build
173
+ ...build,
174
+ rollupOptions: {
175
+ output: {
176
+ manualChunks: trunkFn,
177
+ ...(_a = build.rollupOptions) == null ? void 0 : _a.output
178
+ },
179
+ ...build.rollupOptions
180
+ }
155
181
  },
156
182
  plugins: [
157
183
  vue(),
@@ -180,12 +206,12 @@ function definePageBuildConfig(option) {
180
206
  htmlInjectPlugin({
181
207
  BUILD_TIME: envs.stamp,
182
208
  BUILD_MODE: envs.mode,
183
- BUILD_VERSION: gitInfo.hash,
209
+ BUILD_VERSION: (gitInfo == null ? void 0 : gitInfo.hash) || "",
184
210
  ...envs.viteEnvs,
185
211
  ...define
186
212
  }),
187
213
  ...plugins,
188
- command === "build" && envs.deployTo ? viteDeployPlugin({
214
+ command === "build" && envs.deployTo && !onlyBuild && gitInfo ? viteDeployPlugin({
189
215
  deployTo: envs.deployTo,
190
216
  user: envs.deployUser,
191
217
  key: envs.deployKey,
@@ -197,7 +223,7 @@ function definePageBuildConfig(option) {
197
223
  }
198
224
  }
199
225
  }) : null,
200
- command === "build" && envs.sentryAuthToken ? sentryVitePlugin({
226
+ command === "build" && envs.sentryAuthToken && !onlyBuild ? sentryVitePlugin({
201
227
  authToken: envs.sentryAuthToken,
202
228
  org: "sentry",
203
229
  url: sentry.url || "https://sentry.seayoo.com/",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/scripts",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "scripts for seayoo web repos",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -25,6 +25,6 @@ interface IBuildEnvs {
25
25
  /**
26
26
  * 获取构建环境配置
27
27
  */
28
- export declare function getBuildEnv(command: "serve" | "build", mode: string): IBuildEnvs;
28
+ export declare function getBuildEnv(command: "serve" | "build", mode: string, onlyBuild?: boolean): IBuildEnvs;
29
29
  export declare function transformEnvs(envs: Record<string, unknown>): Record<string, string>;
30
30
  export {};
@@ -5,6 +5,18 @@ interface ExternalConfig {
5
5
  project?: string;
6
6
  url?: string;
7
7
  };
8
+ /** 仅仅编译 */
9
+ onlyBuild?: boolean;
10
+ /**
11
+ * 手工指定 trunk 合并策略,Record<key, chunk>,即 id.include(key) 则打到 trunk 中
12
+ *
13
+ * 默认 {"naive-ui", html2canvas, thinkingdata, vue, node_modules: "vendor"}
14
+ *
15
+ * 设置的值会给默认值进行合并
16
+ *
17
+ * 也可以手工设定 build.rollupOptions.output.manualChunks 来自定义
18
+ */
19
+ manualChunks?: Record<string, string>;
8
20
  }
9
21
  /**
10
22
  * 导出一个动态的配置工厂函数