Skip to content

Commit 4a747e8

Browse files
committed
Merge branch '3.4' into 4.1
* 3.4: [Encore] Fixed code example for SplitChunks Fixing type [Encore] Add a section about the configureRuntimeEnvironment method
2 parents e6ce91b + f380e04 commit 4a747e8

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

components/finder.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ the Finder instance.
5151

5252
.. tip::
5353

54-
A Finder instance is a PHP :phpclass:`Iterator`. So, in addition to iterating over the
54+
A Finder instance is a PHP :phpclass:`IteratorAggregate`. So, in addition to iterating over the
5555
Finder with ``foreach``, you can also convert it to an array with the
56-
:phpfunction:`iterator_to_array` method, or get the number of items with
56+
:phpfunction:`iterator_to_array` function, or get the number of items with
5757
:phpfunction:`iterator_count`.
5858

5959
.. caution::

frontend/encore/advanced-config.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,53 @@ prefer to build configs separately, pass the ``--config-name`` option:
9595
9696
$ yarn encore dev --config-name firstConfig
9797
98+
Generating a Webpack Configuration Object without using the Command-Line Interface
99+
----------------------------------------------------------------------------------
100+
101+
Ordinarily you would use your ``webpack.config.js`` file by calling Encore
102+
from the command-line interface. But sometimes, having access to the generated
103+
Webpack configuration can be required by tools that don't use Encore (for
104+
instance a test-runner such as `Karma`_).
105+
106+
The problem is that if you try generating that Webpack configuration object
107+
without using the ``encore`` command you will encounter the following error:
108+
109+
.. code-block:: text
110+
111+
Error: Encore.setOutputPath() cannot be called yet because the runtime environment doesn't appear to be configured. Make sure you're using the encore executable or call Encore.configureRuntimeEnvironment() first if you're purposely not calling Encore directly.
112+
113+
The reason behind that message is that Encore needs to know a few thing before
114+
being able to create a configuration object, the most important one being what
115+
the target environment is.
116+
117+
To solve this issue you can use ``configureRuntimeEnvironment``. This method
118+
must be called from a JavaScript file **before** requiring ``webpack.config.js``.
119+
120+
For instance:
121+
122+
.. code-block:: javascript
123+
124+
const Encore = require('@symfony/webpack-encore');
125+
126+
// Set the runtime environment
127+
Encore.configureRuntimeEnvironment('dev');
128+
129+
// Retrieve the Webpack configuration object
130+
const webpackConfig = require('./webpack.config');
131+
132+
If needed, you can also pass to that method all the options that you would
133+
normally use from the command-line interface:
134+
135+
.. code-block:: javascript
136+
137+
Encore.configureRuntimeEnvironment('dev-server', {
138+
// Same options you would use with the
139+
// CLI utility, with their name in camelCase.
140+
https: true,
141+
keepPublicPath: true,
142+
});
143+
98144
.. _`configuration options`: https://webpack.js.org/configuration/
99145
.. _`Webpack's watchOptions`: https://webpack.js.org/configuration/watch/#watchoptions
100146
.. _`array of configurations`: https://github.com/webpack/docs/wiki/configuration#multiple-configurations
147+
.. _`Karma`: https://karma-runner.github.io

frontend/encore/split-chunks.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ this plugin with the ``configureSplitChunks()`` function:
5959
+ .configureSplitChunks(function(splitChunks) {
6060
+ // change the configuration
6161
+ splitChunks.minSize = 0;
62-
+ }
62+
+ })
6363
6464
.. _`SplitChunksPlugin from Webpack`: https://webpack.js.org/plugins/split-chunks-plugin/

0 commit comments

Comments
 (0)