You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #10441 [Encore] Add a section about the configureRuntimeEnvironment method (Lyrkan, weaverryan)
This PR was merged into the 3.4 branch.
Discussion
----------
[Encore] Add a section about the configureRuntimeEnvironment method
This PR adds some info about the `configureRuntimeEnvironment(...)` method of Encore.
I wasn't sure where to put that section, it's not an "advanced config" per-se, but it didn't feel right to add it to the FAQ either... but maybe that's just me?
**Feature PR:** symfony/webpack-encore#115
**Closes:** symfony/webpack-encore#233
Commits
-------
24b3370 minor tweak
653ccff [Encore] Add a section about the configureRuntimeEnvironment method
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
+
constEncore=require('@symfony/webpack-encore');
125
+
126
+
// Set the runtime environment
127
+
Encore.configureRuntimeEnvironment('dev');
128
+
129
+
// Retrieve the Webpack configuration object
130
+
constwebpackConfig=require('./webpack.config');
131
+
132
+
If needed, you can also pass to that method all the options that you would
0 commit comments