@@ -23,6 +23,19 @@ import {
23
23
24
24
const isWindows = process . platform === 'win32' ;
25
25
26
+ /**
27
+ * Represents a configuration object.
28
+ * @typedef {object } BuilderConfig
29
+ * @property {string } entry - The entry point for the configuration
30
+ * @property {boolean } useNodePolyfills - Indicates if Node polyfills are being used
31
+ * @property {boolean } useOwnWorker - Indicates if a custom worker is being used
32
+ * @property {object } custom - Custom configuration.
33
+ * @property {* } localCustom - Local custom data
34
+ * @property {* } preset - The preset configuration
35
+ * @property {string } contentToInject - Content to inject
36
+ * @property {{[key: string]: string} } defineVars - Define vars on build
37
+ */
38
+
26
39
/**
27
40
* Class representing a Dispatcher for build operations.
28
41
* @example
@@ -261,14 +274,8 @@ class Dispatcher {
261
274
* @param {object } currentConfig.preset - The current preset.
262
275
* @param {object } currentConfig.localCustom - The current localCustom.
263
276
* @param {object } currentConfig.memoryFS - The current memoryFS.
264
- * @param {object } config - The configuration object.
265
- * @typedef {object } BuildConfig
266
- * @property {boolean } useNodePolyfills - Indicates whether to use Node polyfills.
267
- * @property {boolean } useOwnWorker - Indicates whether to use a custom worker.
268
- * @property {* } localCustom - Custom configuration specific to the local environment.
269
- * @property {* } preset - Preset configuration for the build.
270
- * @property {string } entry - Path to the temporary entry file for the build.
271
- * @returns {BuildConfig } - Returns the configured build object.
277
+ * @param {BuilderConfig } config - The configuration object.
278
+ * @returns {BuilderConfig } - Returns the configured build object.
272
279
*/
273
280
static configureBuild ( currentConfig , config ) {
274
281
const { useNodePolyfills, useOwnWorker, preset, localCustom, memoryFS } =
@@ -309,7 +316,7 @@ class Dispatcher {
309
316
* @param {string } context.builId - The build id.
310
317
* @param {string } context.handler - The handler preset file.
311
318
* @param {string } context.prebuild - The prebuild preset file.
312
- * @param {BuildConfig } buildConfig - The build configuration object.
319
+ * @param {BuilderConfig } buildConfig - The build configuration object.
313
320
* @returns {Promise<object> } - A promise that resolves to an object containing the prebuild context.
314
321
*/
315
322
static async runPrebuild ( context , buildConfig ) {
@@ -335,6 +342,7 @@ class Dispatcher {
335
342
const filesToInject = prebuildResult ?. filesToInject || null ;
336
343
const workerGlobalVars = prebuildResult ?. workerGlobalVars || null ;
337
344
const builderPlugins = prebuildResult ?. builderPlugins || null ;
345
+ const defineVars = prebuildResult ?. defineVars || null ;
338
346
339
347
/**
340
348
* Object containing code to be injected in a handler.
@@ -393,6 +401,7 @@ class Dispatcher {
393
401
394
402
prebuildContext . builderPlugins = builderPlugins ;
395
403
prebuildContext . codeToInjectInHandler = codeToInjectInHandler ;
404
+ prebuildContext . defineVars = defineVars ;
396
405
397
406
return Promise . resolve ( prebuildContext ) ;
398
407
}
@@ -401,7 +410,7 @@ class Dispatcher {
401
410
* Executes the build process based on the provided build configuration.
402
411
* @param {string } originalEntry - The original entry e.g ./index.js.
403
412
* @param {string } builderCurrent - The builder current e.g esbuild.
404
- * @param {BuildConfig } buildConfig - The build configuration object.
413
+ * @param {BuilderConfig } buildConfig - The build configuration object.
405
414
* @returns {Promise<void> } - A promise that resolves when the build process is completed.
406
415
*/
407
416
static async executeBuild ( originalEntry , builderCurrent , buildConfig ) {
@@ -466,7 +475,8 @@ class Dispatcher {
466
475
{ handler, prebuild } ,
467
476
buildConfig ,
468
477
) ;
469
- const { codeToInjectInHandler, builderPlugins } = prebuildContext ;
478
+ const { codeToInjectInHandler, builderPlugins, defineVars } =
479
+ prebuildContext ;
470
480
471
481
// inject code in handler (build is necessary to pull the modules,
472
482
// this is not a simples code append)
@@ -490,6 +500,11 @@ class Dispatcher {
490
500
491
501
Dispatcher . setVulcanLibAbsolutePath ( buildConfig . entry ) ;
492
502
503
+ // prebuildContext.defineVars
504
+ if ( defineVars ) {
505
+ buildConfig . defineVars = defineVars ;
506
+ }
507
+
493
508
await Dispatcher . executeBuild ( this . entry , this . builder , buildConfig ) ;
494
509
495
510
if ( postbuild ) {
0 commit comments