@@ -18,7 +18,7 @@ async function deleteOldDir() {
18
18
await fs . rm ( outdir , { recursive : true , force : true } )
19
19
}
20
20
21
- async function runWebpack ( isWithoutKatex , isWithoutTiktoken , callback ) {
21
+ async function runWebpack ( isWithoutKatex , isWithoutTiktoken , minimal , callback ) {
22
22
const shared = [
23
23
'preact' ,
24
24
'webextension-polyfill' ,
@@ -70,6 +70,12 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
70
70
concatenateModules : ! isAnalyzing ,
71
71
} ,
72
72
plugins : [
73
+ minimal
74
+ ? undefined
75
+ : new webpack . ProvidePlugin ( {
76
+ process : 'process/browser.js' ,
77
+ Buffer : [ 'buffer' , 'Buffer' ] ,
78
+ } ) ,
73
79
new ProgressBarPlugin ( {
74
80
format : ' build [:bar] :percent (:elapsed seconds)' ,
75
81
clear : false ,
@@ -97,6 +103,14 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
97
103
extensions : [ '.jsx' , '.mjs' , '.js' ] ,
98
104
alias : {
99
105
parse5 : path . resolve ( __dirname , 'node_modules/parse5' ) ,
106
+ ...( minimal
107
+ ? { }
108
+ : {
109
+ util : path . resolve ( __dirname , 'node_modules/util' ) ,
110
+ buffer : path . resolve ( __dirname , 'node_modules/buffer' ) ,
111
+ stream : 'stream-browserify' ,
112
+ crypto : 'crypto-browserify' ,
113
+ } ) ,
100
114
} ,
101
115
} ,
102
116
module : {
@@ -206,7 +220,7 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
206
220
} ,
207
221
}
208
222
: { } ,
209
- isWithoutKatex && isWithoutTiktoken
223
+ minimal
210
224
? {
211
225
test : / s t y l e s \. s c s s $ / ,
212
226
loader : 'string-replace-loader' ,
@@ -220,6 +234,32 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
220
234
} ,
221
235
}
222
236
: { } ,
237
+ minimal
238
+ ? {
239
+ test : / i n d e x \. m j s $ / ,
240
+ loader : 'string-replace-loader' ,
241
+ options : {
242
+ multiple : [
243
+ {
244
+ search : 'import { generateAnswersWithChatGLMApi }' ,
245
+ replace : '//' ,
246
+ } ,
247
+ {
248
+ search : 'await generateAnswersWithChatGLMApi' ,
249
+ replace : '//' ,
250
+ } ,
251
+ {
252
+ search : 'chatglmTurbo' ,
253
+ replace : '//' ,
254
+ } ,
255
+ {
256
+ search : "'chatglmTurbo" ,
257
+ replace : '//' ,
258
+ } ,
259
+ ] ,
260
+ } ,
261
+ }
262
+ : { } ,
223
263
] ,
224
264
} ,
225
265
} )
@@ -305,13 +345,15 @@ async function build() {
305
345
// )
306
346
// await new Promise((r) => setTimeout(r, 5000))
307
347
await runWebpack (
348
+ true ,
308
349
true ,
309
350
true ,
310
351
generateWebpackCallback ( ( ) => finishOutput ( '-without-katex-and-tiktoken' ) ) ,
311
352
)
312
353
await new Promise ( ( r ) => setTimeout ( r , 10000 ) )
313
354
}
314
355
await runWebpack (
356
+ false ,
315
357
false ,
316
358
false ,
317
359
generateWebpackCallback ( ( ) => finishOutput ( '' ) ) ,
0 commit comments