Skip to content

Encore (advanced): add documentation for configureLoaderRule() method #11075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 25, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions frontend/encore/advanced-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,47 @@ normally use from the command-line interface:
keepPublicPath: true,
});

Having the full control on Loaders Rules
----------------------------------------

The method ``configureLoaderRule()`` provide a clean way to configure Webpack loaders rules (``module.rules``, see `Configuration <https://webpack.js.org/concepts/loaders/#configuration>`_).

This is a low-level method. Any of your modifications will be applied just before pushing the loaders rules to Webpack.
It means that you can override configuration provided by Encore, so maybe you will break things. Be careful when using it.

A useful usage would be for configuring the ``eslint-loader`` to lint Vue files too.
The following code is equivalent:

.. code-block:: javascript

// Before
const webpackConfig = Encore.getWebpackConfig();

const eslintLoader = webpackConfig.module.rules.find(rule => rule.loader === 'eslint-loader');
eslintLoader.test = /\.(jsx?|vue)$/;

return webpackConfig;

// After
Encore.configureLoaderRule('eslint', loaderRule => {
loaderRule.test = /\.(jsx?|vue)$/
});

return Encore.getWebpackConfig();

The following loaders are configurable with ``configureLoaderRule()``:
- ``javascript`` (alias ``js``)
- ``css``
- ``images``
- ``fonts``
- ``sass`` (alias ``scss``)
- ``less``
- ``stylus``
- ``vue``
- ``eslint``
- ``typescript`` (alias ``ts``)
- ``handlebars``

.. _`configuration options`: https://webpack.js.org/configuration/
.. _`Webpack's watchOptions`: https://webpack.js.org/configuration/watch/#watchoptions
.. _`array of configurations`: https://github.com/webpack/docs/wiki/configuration#multiple-configurations
Expand Down