@@ -3191,6 +3191,18 @@ def phase_memory_initializer(memfile):
3191
3191
final_js += '.mem.js'
3192
3192
3193
3193
3194
+ def create_worker_file (input_file , target_dir , output_file ):
3195
+ output_file = os .path .join (target_dir , output_file )
3196
+ input_file = utils .path_from_root (input_file )
3197
+ contents = shared .read_and_preprocess (input_file , expand_macros = True )
3198
+ write_file (output_file , contents )
3199
+
3200
+ # Minify the worker JS files file in optimized builds
3201
+ if (settings .OPT_LEVEL >= 1 or settings .SHRINK_LEVEL >= 1 ) and not settings .DEBUG_LEVEL :
3202
+ contents = building .acorn_optimizer (output_file , ['minifyWhitespace' ], return_output = True )
3203
+ write_file (output_file , contents )
3204
+
3205
+
3194
3206
@ToolchainProfiler .profile_block ('final emitting' )
3195
3207
def phase_final_emitting (options , state , target , wasm_target , memfile ):
3196
3208
global final_js
@@ -3203,36 +3215,15 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
3203
3215
3204
3216
target_dir = os .path .dirname (os .path .abspath (target ))
3205
3217
if settings .PTHREADS :
3206
- worker_output = os .path .join (target_dir , settings .PTHREAD_WORKER_FILE )
3207
- contents = shared .read_and_preprocess (utils .path_from_root ('src/worker.js' ), expand_macros = True )
3208
- write_file (worker_output , contents )
3209
-
3210
- # Minify the worker.js file in optimized builds
3211
- if (settings .OPT_LEVEL >= 1 or settings .SHRINK_LEVEL >= 1 ) and not settings .DEBUG_LEVEL :
3212
- minified_worker = building .acorn_optimizer (worker_output , ['minifyWhitespace' ], return_output = True )
3213
- write_file (worker_output , minified_worker )
3218
+ create_worker_file ('src/worker.js' , target_dir , settings .PTHREAD_WORKER_FILE )
3214
3219
3215
3220
# Deploy the Wasm Worker bootstrap file as an output file (*.ww.js)
3216
3221
if settings .WASM_WORKERS == 1 :
3217
- worker_output = os .path .join (target_dir , settings .WASM_WORKER_FILE )
3218
- contents = shared .read_and_preprocess (shared .path_from_root ('src/wasm_worker.js' ), expand_macros = True )
3219
- write_file (worker_output , contents )
3220
-
3221
- # Minify the wasm_worker.js file in optimized builds
3222
- if (settings .OPT_LEVEL >= 1 or settings .SHRINK_LEVEL >= 1 ) and not settings .DEBUG_LEVEL :
3223
- minified_worker = building .acorn_optimizer (worker_output , ['minifyWhitespace' ], return_output = True )
3224
- write_file (worker_output , minified_worker )
3222
+ create_worker_file ('src/wasm_worker.js' , target_dir , settings .WASM_WORKER_FILE )
3225
3223
3226
3224
# Deploy the Audio Worklet module bootstrap file (*.aw.js)
3227
3225
if settings .AUDIO_WORKLET == 1 :
3228
- worklet_output = os .path .join (target_dir , settings .AUDIO_WORKLET_FILE )
3229
- contents = shared .read_and_preprocess (shared .path_from_root ('src' , 'audio_worklet.js' ), expand_macros = True )
3230
- utils .write_file (worklet_output , contents )
3231
-
3232
- # Minify the audio_worklet.js file in optimized builds
3233
- if (settings .OPT_LEVEL >= 1 or settings .SHRINK_LEVEL >= 1 ) and not settings .DEBUG_LEVEL :
3234
- minified_worker = building .acorn_optimizer (worklet_output , ['minifyWhitespace' ], return_output = True )
3235
- utils .write_file (worklet_output , minified_worker )
3226
+ create_worker_file ('src/audio_worklet.js' , target_dir , settings .AUDIO_WORKLET_FILE )
3236
3227
3237
3228
if settings .MODULARIZE :
3238
3229
modularize ()
0 commit comments