Skip to content

Commit fd8e772

Browse files
committed
feature symfony#11075 Encore (advanced): add documentation for configureLoaderRule() method (Kocal, Lyrkan, weaverryan)
This PR was merged into the 3.4 branch. Discussion ---------- Encore (advanced): add documentation for `configureLoaderRule()` method Hey, This PR add a new entry in the advanced configuration of Webpack Encore, which explains how to use the new method `configureLoaderRule()`. Ref: symfony/webpack-encore#509 Commits ------- e3d43b9 minor tweak 71fd3b7 Apply suggestions from code review c02322c Encore (advanced): add documentation for `configureLoaderRule()` method
2 parents 284f1ef + e3d43b9 commit fd8e772

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

frontend/encore/advanced-config.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,47 @@ normally use from the command-line interface:
170170
keepPublicPath: true,
171171
});
172172
173+
Having the full control on Loaders Rules
174+
----------------------------------------
175+
176+
The method ``configureLoaderRule()`` provides a clean way to configure Webpack loaders rules (``module.rules``, see `Configuration <https://webpack.js.org/concepts/loaders/#configuration>`_).
177+
178+
This is a low-level method. All your modifications will be applied just before pushing the loaders rules to Webpack.
179+
It means that you can override the default configuration provided by Encore, which may break things. Be careful when using it.
180+
181+
One use might be to configure the ``eslint-loader`` to lint Vue files too.
182+
The following code is equivalent:
183+
184+
.. code-block:: javascript
185+
186+
// Manually
187+
const webpackConfig = Encore.getWebpackConfig();
188+
189+
const eslintLoader = webpackConfig.module.rules.find(rule => rule.loader === 'eslint-loader');
190+
eslintLoader.test = /\.(jsx?|vue)$/;
191+
192+
return webpackConfig;
193+
194+
// Using Encore.configureLoaderRule()
195+
Encore.configureLoaderRule('eslint', loaderRule => {
196+
loaderRule.test = /\.(jsx?|vue)$/
197+
});
198+
199+
return Encore.getWebpackConfig();
200+
201+
The following loaders are configurable with ``configureLoaderRule()``:
202+
- ``javascript`` (alias ``js``)
203+
- ``css``
204+
- ``images``
205+
- ``fonts``
206+
- ``sass`` (alias ``scss``)
207+
- ``less``
208+
- ``stylus``
209+
- ``vue``
210+
- ``eslint``
211+
- ``typescript`` (alias ``ts``)
212+
- ``handlebars``
213+
173214
.. _`configuration options`: https://webpack.js.org/configuration/
174215
.. _`Webpack's watchOptions`: https://webpack.js.org/configuration/watch/#watchoptions
175216
.. _`array of configurations`: https://github.com/webpack/docs/wiki/configuration#multiple-configurations

0 commit comments

Comments
 (0)