@@ -410,6 +410,88 @@ In reality, each environment differs only somewhat from others. This means that
410
410
all environments share a large base of common configuration, which is put in
411
411
files directly in the ``config/packages/ `` directory.
412
412
413
+ .. tip ::
414
+
415
+ .. versionadded :: 5.3
416
+
417
+ The ability to defined different environments in a single file was
418
+ introduced in Symfony 5.3.
419
+
420
+ You can also define options for different environments in a single
421
+ configuration file using the special ``when `` keyword:
422
+
423
+ .. configuration-block ::
424
+
425
+ .. code-block :: yaml
426
+
427
+ # config/packages/webpack_encore.yaml
428
+ webpack_encore :
429
+ # ...
430
+ output_path : ' %kernel.project_dir%/public/build'
431
+ strict_mode : true
432
+ cache : false
433
+
434
+ # cache is enabled only in the "prod" environment
435
+ when@prod :
436
+ webpack_encore :
437
+ cache : true
438
+
439
+ # disable strict mode only in the "test" environment
440
+ when@test :
441
+ webpack_encore :
442
+ strict_mode : false
443
+
444
+ .. code-block :: xml
445
+
446
+ <!-- config/packages/webpack_encore.xml -->
447
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
448
+ <container xmlns =" http://symfony.com/schema/dic/services"
449
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
450
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
451
+ https://symfony.com/schema/dic/services/services-1.0.xsd
452
+ http://symfony.com/schema/dic/symfony
453
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
454
+ <webpack-encore : config
455
+ output-path =" %kernel.project_dir%/public/build"
456
+ strict-mode =" true"
457
+ cache =" false"
458
+ />
459
+
460
+ <!-- cache is enabled only in the "test" environment -->
461
+ <when env =" prod" >
462
+ <webpack-encore : config cache =" true" />
463
+ </when >
464
+
465
+ <!-- disable strict mode only in the "test" environment -->
466
+ <when env =" test" >
467
+ <webpack-encore : config strict-mode =" false" />
468
+ </when >
469
+ </container >
470
+
471
+ .. code-block :: php
472
+
473
+ // config/packages/framework.php
474
+ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
475
+ use Symfony\Config\WebpackEncoreConfig;
476
+
477
+ return static function (WebpackEncoreConfig $webpackEncore, ContainerConfigurator $container) {
478
+ $webpackEncore
479
+ ->outputPath('%kernel.project_dir%/public/build')
480
+ ->strictMode(true)
481
+ ->cache(false)
482
+ ;
483
+
484
+ // cache is enabled only in the "prod" environment
485
+ if ('prod' === $container->env()) {
486
+ $webpackEncore->cache(true);
487
+ }
488
+
489
+ // disable strict mode only in the "test" environment
490
+ if ('test' === $container->env()) {
491
+ $webpackEncore->strictMode(false);
492
+ }
493
+ };
494
+
413
495
.. seealso ::
414
496
415
497
See the ``configureContainer() `` method of
0 commit comments