@cloudbase/ai 3.3.14-beta.1 → 3.6.4-alpha.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.
Files changed (64) hide show
  1. package/dist/cjs/AI.d.ts +5 -3
  2. package/dist/cjs/AI.js +64 -24
  3. package/dist/cjs/errors.d.ts +10 -0
  4. package/dist/cjs/errors.js +38 -0
  5. package/dist/cjs/index.d.ts +3 -1
  6. package/dist/cjs/index.js +14 -6
  7. package/dist/cjs/models/image-model.d.ts +2 -1
  8. package/dist/cjs/models/image-model.js +33 -12
  9. package/dist/cjs/type.d.ts +3 -1
  10. package/dist/cjs/type.js +1 -1
  11. package/dist/cjs/utils.d.ts +1 -1
  12. package/dist/cjs/utils.js +9 -4
  13. package/dist/esm/AI.d.ts +5 -3
  14. package/dist/esm/AI.js +64 -24
  15. package/dist/esm/errors.d.ts +10 -0
  16. package/dist/esm/errors.js +35 -0
  17. package/dist/esm/index.d.ts +3 -1
  18. package/dist/esm/index.js +14 -6
  19. package/dist/esm/models/image-model.d.ts +2 -1
  20. package/dist/esm/models/image-model.js +33 -12
  21. package/dist/esm/type.d.ts +3 -1
  22. package/dist/esm/type.js +1 -1
  23. package/dist/esm/utils.d.ts +1 -1
  24. package/dist/esm/utils.js +9 -4
  25. package/dist/miniprogram/index.js +1 -1
  26. package/dist/miniprogram/index.js.LICENSE.txt +2 -2
  27. package/package.json +8 -4
  28. package/.eslintignore +0 -2
  29. package/.eslintrc.js +0 -15
  30. package/src/AI.ts +0 -154
  31. package/src/bot/index.ts +0 -278
  32. package/src/bot/types.ts +0 -165
  33. package/src/eventsource_parser/index.ts +0 -2
  34. package/src/eventsource_parser/parse.ts +0 -169
  35. package/src/eventsource_parser/stream.ts +0 -35
  36. package/src/eventsource_parser/types.ts +0 -90
  37. package/src/index.ts +0 -156
  38. package/src/models/Ark/index.ts +0 -94
  39. package/src/models/Ark/type.ts +0 -82
  40. package/src/models/DashScope/index.ts +0 -97
  41. package/src/models/DashScope/type.ts +0 -76
  42. package/src/models/DeepSeek/index.ts +0 -80
  43. package/src/models/Default/index.ts +0 -70
  44. package/src/models/HunYuan/index.ts +0 -94
  45. package/src/models/HunYuan/type.ts +0 -85
  46. package/src/models/HunYuan/util.ts +0 -60
  47. package/src/models/HunYuanBeta/index.ts +0 -83
  48. package/src/models/HunYuanExp/index.ts +0 -80
  49. package/src/models/HunYuanOpen/index.ts +0 -83
  50. package/src/models/Moonshot/index.ts +0 -95
  51. package/src/models/Moonshot/type.ts +0 -82
  52. package/src/models/Yi/index.ts +0 -100
  53. package/src/models/Yi/type.ts +0 -77
  54. package/src/models/ZhiPu/index.ts +0 -104
  55. package/src/models/ZhiPu/type.ts +0 -71
  56. package/src/models/image-model.ts +0 -59
  57. package/src/models/index.ts +0 -41
  58. package/src/models/model.ts +0 -425
  59. package/src/type.ts +0 -349
  60. package/src/utils.ts +0 -183
  61. package/tsconfig.esm.json +0 -16
  62. package/tsconfig.json +0 -16
  63. package/webpack/web.prod.js +0 -100
  64. package/webpack/webpack.miniprogram.js +0 -24
package/src/type.ts DELETED
@@ -1,349 +0,0 @@
1
- export abstract class SimpleChatModel {
2
- public abstract doGenerate(data: BaseChatModelInput, options?: ReqOptions): Promise<DoGenerateOutput>
3
-
4
- public abstract doStream(data: BaseChatModelInput, options?: ReqOptions): Promise<DoStreamOutput>
5
- }
6
-
7
- type RawResponse = { rawResponse?: any }
8
-
9
- export type DoGenerateOutput = BaseDoGenerateOutput & RawResponse
10
-
11
- export type DoStreamOutput = AsyncIterableReadableStream<BaseDoStreamOutputChunk & RawResponse>
12
-
13
- export type ChatModelConstructor = typeof SimpleChatModel
14
-
15
- export type AsyncIterableReadableStream<T> = ReadableStream<T> & {
16
- [Symbol.asyncIterator]: () => { next(): Promise<IteratorResult<T>> }
17
- }
18
-
19
- export interface IModelReqInput {
20
- url: string
21
- headers?: Record<string, string>
22
- data?: Object
23
- stream?: boolean
24
- timeout?: number
25
- }
26
-
27
- export type ModelReq = <T extends IModelReqInput>(
28
- props: T,
29
- ) => T['stream'] extends true ? Promise<ReadableStream<Uint8Array>> : Promise<Object>
30
-
31
- export interface IBotReqInput {
32
- url: string
33
- method: string
34
- headers?: Record<string, string>
35
- data?: Object
36
- stream?: boolean
37
- timeout?: number
38
- }
39
-
40
- export interface ReqOptions {
41
- timeout?: number
42
- }
43
-
44
- export type BotReq = <T extends IBotReqInput>(
45
- props: T,
46
- ) => T['stream'] extends true ? Promise<ReadableStream<Uint8Array>> : Promise<Object>
47
-
48
- export type UserMessage = {
49
- role: 'user'
50
- content: string
51
- }
52
-
53
- export type SystemMessage = {
54
- role: 'system'
55
- content: string
56
- }
57
-
58
- export type AssistantMessage = PlainAssistantMessage | ToolCallAssistantMessage
59
-
60
- export type PlainAssistantMessage = {
61
- role: 'assistant'
62
- content: string
63
- }
64
-
65
- export type ToolCallAssistantMessage = {
66
- role: 'assistant'
67
- tool_calls: Array<ToolCall>
68
- content?: string
69
- }
70
-
71
- export type ToolMessage = {
72
- role: 'tool'
73
- tool_call_id: string
74
- content: string
75
- }
76
-
77
- export type ChatModelMessage = UserMessage | SystemMessage | AssistantMessage | ToolMessage
78
-
79
- export type FunctionTool = {
80
- name: string
81
- description: string
82
- fn: CallableFunction
83
- parameters: object
84
- }
85
-
86
- // #region 大模型标准输入类型
87
- export interface BaseChatModelInput {
88
- model: string
89
- messages: Array<ChatModelMessage>
90
- temperature?: number
91
- top_p?: number
92
- tools?: Array<ModelTool>
93
- tool_choice?: 'none' | 'auto' | 'custom'
94
- }
95
-
96
- /**
97
- * 给 LLM 发请求时要传的工具
98
- */
99
- export type ModelTool = {
100
- type: string
101
- function: ModelToolFunction
102
- }
103
-
104
- /**
105
- * 给 LLM 发请求时要传的工具函数
106
- */
107
- export type ModelToolFunction = {
108
- name: string
109
- description: string
110
- /**
111
- * 描述函数参数的 JSON Schema
112
- */
113
- parameters: object
114
- }
115
- // #endregion
116
-
117
- // #region 大模型标准响应类型
118
- export type ToolCall = {
119
- id: string
120
- type: string
121
- function: { name: string; arguments: string }
122
- }
123
-
124
- type FinishReason = 'tool_calls' | (string & {})
125
-
126
- export type Usage = {
127
- completion_tokens: number
128
- prompt_tokens: number
129
- total_tokens: number
130
- }
131
-
132
- export interface BaseDoGenerateOutput {
133
- choices?: Array<{
134
- finish_reason?: FinishReason
135
- message?: ChatModelMessage
136
- }>
137
- usage?: Usage
138
- }
139
-
140
- export interface BaseDoStreamOutputChunk {
141
- choices?: Array<{
142
- finish_reason?: FinishReason
143
- delta?: ChatModelMessage
144
- }>
145
- usage?: Usage
146
- }
147
- // #endregion
148
-
149
- // #region Image Model Types
150
- /**
151
- * 图片生成输入参数
152
- */
153
- export interface ImageGenerateInput {
154
- model: string // 模型名称,例如 'hunyuan-image'、'dall-e-3'
155
- prompt: string // 用于描述要生成的图片内容
156
- size?: string // 尺寸
157
- n?: number // 张数
158
- [key: string]: unknown // 允许额外的厂商特定参数
159
- }
160
-
161
- /**
162
- * 图片编辑输入参数
163
- */
164
- export interface ImageEditInput {
165
- model: string
166
- prompt: string
167
- size?: string // 尺寸
168
- n?: number // 张数
169
- [key: string]: unknown // 允许额外的厂商特定参数
170
- }
171
-
172
- export interface HunyuanGenerateImageInput {
173
- model: 'hunyuan-image'
174
- /** 用来生成图像的文本描述 */
175
- prompt: string
176
- /**
177
- * 模型版本,支持 v1.8.1 和 v1.9,默认版本 v1.8.1
178
- * - v1.8.1: 采用二阶段模型支持文生图任务,针对图像细节、稳定性等要求高的任务较为合适
179
- * - v1.9: 采用模型矩阵能力支持文生图任务,后端由人像、游戏、通用模型,以及各类功能插件组成,灵活适配多种文生图任务
180
- */
181
- version?: 'v1.8.1' | 'v1.9' | (string & {})
182
- /**
183
- * 图片尺寸,默认 "1024x1024"
184
- * v1.9 仅支持以下几个尺寸:
185
- * - 1024x1024
186
- * - 1024x768, 1152x864
187
- * - 768x1024, 864x1152
188
- * - 1280x768 (16:9)
189
- * - 768x1280 (9:16)
190
- * - 1280x720 (16:9)
191
- * - 720x1280 (9:16)
192
- *
193
- * 支持用户自定义尺寸,但输入尺寸只支持 768-1280 之间且为 64 的倍数的数字
194
- */
195
- size?: string
196
- /**
197
- * 仅 v1.9 支持,负向词
198
- * 如果不传则使用各个模型内部的默认负向词
199
- */
200
- negative_prompt?: string
201
- /**
202
- * 仅 v1.9 支持,可指定风格:
203
- * - 古风二次元风格
204
- * - 都市二次元风格
205
- * - 悬疑风格
206
- * - 校园风格
207
- * - 都市异能风格
208
- */
209
- style?: '古风二次元风格' | '都市二次元风格' | '悬疑风格' | '校园风格' | '都市异能风格' | (string & {})
210
- /**
211
- * 为 true 时对 prompt 进行改写,实际生成的图片会使用改写后的 prompt 进行生成
212
- * 多数场景可提升生成的图片效果,默认为 true
213
- */
214
- revise?: boolean
215
- /**
216
- * 生成图片个数,默认为 1
217
- * 目前只支持生成一张,固定为 1,传其他的值会报错
218
- */
219
- n?: number
220
- /**
221
- * 业务自定义水印内容
222
- * 限制 16 个字符长度(不区分中英文),生成在图片右下角
223
- */
224
- footnote?: string
225
- /**
226
- * 生成种子,仅当生成图片数为 1 时生效
227
- * 范围 [1, 4294967295],不传时默认随机
228
- */
229
- seed?: number
230
- }
231
-
232
- export interface HunyuanARGenerateImageInput {
233
- /** 模型名称:hunyuan-image-v3.0-v1.0.4(推荐)或 hunyuan-image-v3.0-v1.0.1 */
234
- model: 'hunyuan-image-v3.0-v1.0.4' | 'hunyuan-image-v3.0-v1.0.1'
235
- /** 生成图片使用的文本,不超过 8192 字符 */
236
- prompt: string
237
- /**
238
- * 图片尺寸,格式 "${宽}x${高}",默认 "1024x1024"
239
- * hunyuan-image-v3.0-v1.0.4:宽高 [512, 2048],面积不超过 1024x1024
240
- * hunyuan-image-v3.0-v1.0.1:支持固定尺寸列表
241
- */
242
- size?: string
243
- /** 生成种子,仅当生成图片数为 1 时生效,范围 [1, 4294967295] */
244
- seed?: number
245
- /** 业务自定义水印内容,限制 16 字符,生成在图片右下角 */
246
- footnote?: string
247
- /** 是否对 prompt 改写,默认开启。改写会增加约 30s 耗时 */
248
- revise?: { value: boolean }
249
- /** 改写是否开启 thinking 模式,默认开启。开启后效果提升但耗时增加(最大 60s) */
250
- enable_thinking?: { value: boolean }
251
- }
252
-
253
- export interface HunyuanARGenerateImageOutput {
254
- /** 此次请求的 id */
255
- id: string
256
- /** unix 时间戳 */
257
- created: number
258
- /** 返回的图片生成内容 */
259
- data: Array<{
260
- /** 生成的图片 url,有效期 24 小时 */
261
- url: string
262
- /** 改写后的 prompt */
263
- revised_prompt?: string
264
- }>
265
- }
266
-
267
- export type HunyuanEditImageInput = {
268
- /** 模型名称,本期为 hunyuan-image,即为商品图编辑场景 */
269
- model: 'hunyuan-image' | (string & {})
270
- /** 编辑的文本描述 */
271
- prompt: string
272
- /** 模型版本 */
273
- version?: string
274
- /**
275
- * 图片尺寸,默认 "800x800"
276
- * 支持用户自定义尺寸,但输入尺寸只支持 512-1280 之间
277
- * 目前只支持 1:1、16:9、9:16 三个尺寸
278
- */
279
- size?: string
280
- /**
281
- * 生成图片个数,默认为 1
282
- * 目前只支持生成一张,固定为 1,传其他的值会报错
283
- */
284
- n?: number
285
- /**
286
- * beta 参数,随机种子
287
- * 范围 [1, 4294967295],不传时默认随机
288
- */
289
- seed?: number
290
- /**
291
- * 业务自定义角标内容
292
- * 限制 16 个字符长度(不区分中英文)
293
- */
294
- footnote?: string
295
- /**
296
- * 图 base64 编码,大小不超过 6M
297
- * 支持 jpg/jpeg 格式,和 image_url 二选一
298
- * 长短边比例要求 2:1 内
299
- */
300
- image?: string
301
- /**
302
- * 图片 url
303
- * 长短边比例要求 2:1 内,和 image 二选一
304
- */
305
- image_url?: string
306
- } & (
307
- | {
308
- mask: string
309
- mask_url?: never
310
- }
311
- | {
312
- mask?: never
313
- mask_url: string
314
- }
315
- )
316
-
317
- /**
318
- * 混元图片生成输出
319
- */
320
- export interface HunyuanGenerateImageOutput {
321
- /** 此次请求的 id */
322
- id: string
323
- /** unix 时间戳 */
324
- created: number
325
- /** 返回的图片生成内容 */
326
- data: Array<{
327
- /** 生成的图片 url,有效期为 24 小时 */
328
- url: string
329
- /** 原 prompt 改写后的文本。若 revise 为 false,则为原 prompt */
330
- revised_prompt?: string
331
- }>
332
- }
333
-
334
- /**
335
- * 混元图片编辑输出
336
- */
337
- export interface HunyuanEditImageOutput {
338
- /** 此次请求的 id */
339
- id: string
340
- /** unix 时间戳 */
341
- created: number
342
- /** 返回的图片生成内容 */
343
- data: Array<{
344
- /** 生成的图片 url,有效期为 24 小时 */
345
- url: string
346
- }>
347
- }
348
-
349
- // #endregion
package/src/utils.ts DELETED
@@ -1,183 +0,0 @@
1
- import { TransformStream as _TransformStream, ReadableStream as _ReadableStream } from 'web-streams-polyfill'
2
- import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter'
3
- import { createParser, type EventSourceParser, type ParsedEvent } from './eventsource_parser'
4
- import type {
5
- AsyncIterableReadableStream,
6
- ChatModelMessage,
7
- ToolCallAssistantMessage,
8
- ModelTool,
9
- FunctionTool,
10
- } from './type'
11
- import { TextDecoder } from 'text-encoding-shim'
12
-
13
- export const ReadableStream = _ReadableStream as {
14
- prototype: ReadableStream
15
-
16
- new (
17
- underlyingSource: UnderlyingByteSource,
18
- strategy?: {
19
- highWaterMark?: number
20
- },
21
- ): ReadableStream<Uint8Array>
22
- new <R = any>(underlyingSource: UnderlyingDefaultSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>
23
- new <R = any>(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>
24
- }
25
-
26
- export const TransformStream = _TransformStream as {
27
- prototype: TransformStream
28
-
29
- new <I = any, O = any>(
30
- transformer?: Transformer<I, O>,
31
- writableStrategy?: QueuingStrategy<I>,
32
- readableStrategy?: QueuingStrategy<O>,
33
- ): TransformStream<I, O>
34
- }
35
-
36
- export const createEventSourceParserTransformStream = () => {
37
- let parser!: EventSourceParser
38
-
39
- return new TransformStream<string, ParsedEvent>({
40
- start(controller) {
41
- parser = createParser((event) => {
42
- if (event.type === 'event') {
43
- controller.enqueue(event)
44
- }
45
- })
46
- },
47
- transform(chunk) {
48
- parser.feed(chunk)
49
- },
50
- })
51
- }
52
-
53
- export const toPolyfillReadable = createReadableStreamWrapper(ReadableStream)
54
-
55
- export class TextDecoderStream {
56
- private handle: TextDecoder
57
-
58
- private transform = new TransformStream({
59
- transform: (chunk, controller) => {
60
- const value = this.handle.decode(new Uint8Array(chunk), { stream: true })
61
-
62
- if (value) {
63
- controller.enqueue(value)
64
- }
65
- },
66
- flush: (controller) => {
67
- const value = this.handle.decode()
68
- if (value) {
69
- controller.enqueue(value)
70
- }
71
-
72
- controller.terminate()
73
- },
74
- })
75
-
76
- constructor(encoding = 'utf-8', options: TextDecoderOptions = {}) {
77
- this.handle = new TextDecoder(encoding, options)
78
- }
79
-
80
- get encoding() {
81
- return this.handle.encoding
82
- }
83
-
84
- get fatal() {
85
- return this.handle.fatal
86
- }
87
-
88
- get ignoreBOM() {
89
- return this.handle.ignoreBOM
90
- }
91
-
92
- get readable() {
93
- return this.transform.readable
94
- }
95
-
96
- get writable() {
97
- return this.transform.writable
98
- }
99
-
100
- get [Symbol.toStringTag]() {
101
- return 'TextDecoderStream'
102
- }
103
- }
104
-
105
- export function createAsyncIterable<T>(stream: ReadableStream<T>) {
106
- // eslint-disable-next-line @typescript-eslint/naming-convention
107
- const _stream = stream as AsyncIterableReadableStream<T>
108
- (_stream as any)[Symbol.asyncIterator] = () => {
109
- const reader = stream.getReader()
110
- return {
111
- async next(): Promise<IteratorResult<T>> {
112
- const { done, value } = await reader.read()
113
- return done ? { done: true, value: undefined } : { done: false, value }
114
- },
115
- }
116
- }
117
- return _stream
118
- }
119
-
120
- /**
121
- * 将 SSE 二进制流转换为 T 类型的流
122
- */
123
- export function intoStandardStream<T>(stream: ReadableStream<Uint8Array>): ReadableStream<T> {
124
- return createAsyncIterable(stream
125
- .pipeThrough(new TextDecoderStream())
126
- .pipeThrough(createEventSourceParserTransformStream())
127
- .pipeThrough(new TransformStream<ParsedEvent, T>({
128
- transform(chunk, controller) {
129
- try {
130
- const data = JSON.parse(chunk.data) as T
131
- controller.enqueue(data)
132
- } catch (e) {
133
- if (chunk.data !== '[DONE]') {
134
- console.warn('Error when transforming event source data to json', e, chunk)
135
- } else {
136
- controller.terminate()
137
- }
138
- }
139
- },
140
- }),),)
141
- }
142
-
143
- /**
144
- * 将 SSE 二进制流转换为字符串流
145
- */
146
- export function intoTextStream(stream: ReadableStream<Uint8Array>): AsyncIterableReadableStream<string> {
147
- return createAsyncIterable((toPolyfillReadable(stream) as typeof stream).pipeThrough(new TextDecoderStream()))
148
- }
149
-
150
- export async function readableStream2JsonObject(stream: ReadableStream) {
151
- const s = intoTextStream(stream)
152
- let total = ''
153
- for await (const chunk of s) {
154
- total += chunk
155
- }
156
- return JSON.parse(total)
157
- }
158
-
159
- export function createPromise<T = unknown>() {
160
- let res: (value: T | PromiseLike<T>) => void
161
- let rej: (reason?: any) => void
162
- const promise = new Promise<T>((resolve, reject) => {
163
- res = resolve
164
- rej = reject
165
- })
166
- return { promise, res, rej }
167
- }
168
-
169
- export function isToolCallAssistantMessage(message: ChatModelMessage): message is ToolCallAssistantMessage {
170
- // eslint-disable-next-line eqeqeq
171
- return message.role === 'assistant' && 'tool_calls' in message && message.tool_calls?.[0] != null
172
- }
173
-
174
- export function functionToolToModelTool(tool: FunctionTool): ModelTool {
175
- return {
176
- type: 'function',
177
- function: {
178
- description: tool.description,
179
- name: tool.name,
180
- parameters: tool.parameters,
181
- },
182
- }
183
- }
package/tsconfig.esm.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "es6",
5
- "outDir": "dist/esm",
6
- "rootDir": "src",
7
- },
8
- "include": [
9
- "src/**/*.ts",
10
- "package.json"
11
- ],
12
- "exclude": [
13
- "node_modules",
14
- "dist"
15
- ]
16
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "node16",
5
- "outDir": "dist/cjs",
6
- "rootDir": "src",
7
- },
8
- "include": [
9
- "src/**/*",
10
- "package.json"
11
- ],
12
- "exclude": [
13
- "node_modules",
14
- "dist"
15
- ]
16
- }
@@ -1,100 +0,0 @@
1
- const path = require('path')
2
- const webpack = require('webpack')
3
- const TerserPlugin = require('terser-webpack-plugin')
4
- // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
5
- module.exports = function (options) {
6
- const { context, entry, output, mode, watch, externals, definePlugin = {}, optimization = {} } = options
7
- const isDevelopment = mode !== 'production'
8
- let plugins = [
9
- new webpack.DefinePlugin(definePlugin),
10
- // new BundleAnalyzerPlugin()
11
- ].filter((item) => !!item)
12
-
13
- const BABEL_LOADER = {
14
- loader: 'babel-loader',
15
- options: {
16
- presets: [
17
- [
18
- '@babel/preset-env',
19
- {
20
- modules: false,
21
- targets: {
22
- esmodules: true,
23
- },
24
- },
25
- ],
26
- ],
27
- },
28
- }
29
-
30
- return {
31
- context,
32
- entry,
33
- mode,
34
- watch,
35
- watchOptions: {
36
- ignored: [output.path],
37
- },
38
- output,
39
- externals,
40
- cache: {
41
- type: 'memory',
42
- },
43
- devtool: false,
44
- resolve: {
45
- extensions: ['.ts', '.js', '.json'],
46
- },
47
- module: {
48
- rules: [
49
- {
50
- test: /\.ts$/,
51
- exclude: [/node_modules/],
52
- use: [
53
- BABEL_LOADER,
54
- {
55
- loader: require.resolve('ts-loader'),
56
- options: {
57
- configFile: path.resolve(context, './tsconfig.esm.json'),
58
- },
59
- },
60
- ],
61
- },
62
- {
63
- test: /\.js$/,
64
- exclude: [/node_modules/],
65
- use: [BABEL_LOADER],
66
- },
67
- {
68
- test: /package\.json$/,
69
- loader: 'package-json-cleanup-loader',
70
- options: {
71
- only: ['version'],
72
- },
73
- },
74
- ],
75
- noParse: [/sjcl\.js$/],
76
- },
77
- plugins,
78
- optimization: {
79
- emitOnErrors: false,
80
- removeEmptyChunks: true,
81
- usedExports: true,
82
- ...optimization,
83
- ...(isDevelopment
84
- ? {
85
- minimize: false,
86
- removeAvailableModules: false,
87
- concatenateModules: true,
88
- }
89
- : {
90
- minimizer: [
91
- new TerserPlugin({
92
- test: /\.js(\?.*)?$/i,
93
- cache: false,
94
- parallel: true,
95
- }),
96
- ],
97
- }),
98
- },
99
- }
100
- }
@@ -1,24 +0,0 @@
1
- const path = require('path')
2
-
3
- const params = {
4
- context: path.resolve(__dirname, '../'),
5
- mode: 'production',
6
- watch: false,
7
- entry: path.resolve(__dirname, '../src/index.ts'),
8
- output: {
9
- path: path.resolve(__dirname, '../dist/miniprogram'),
10
- filename: 'index.js',
11
- library: `tcbauth`,
12
- libraryTarget: 'umd',
13
- umdNamedDefine: true,
14
- globalObject: 'typeof window !== "undefined"?window:this',
15
- },
16
- externals: {
17
- },
18
- definePlugin: {
19
- 'process.env.NODE_ENV': JSON.stringify('production'), // 注入环境变量,用于业务代码判断
20
- 'globalThis.IS_MP_BUILD': true,
21
- },
22
- }
23
-
24
- module.exports = require('./web.prod.js')(params)