From 8ef7f9dcef89f80f212c6d2069aaea67a753962c Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Sat, 24 Jun 2017 15:44:42 +0200 Subject: [PATCH 1/2] Add docs for custom loaders --- frontend.rst | 1 + frontend/encore/custom-loaders.rst | 39 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 frontend/encore/custom-loaders.rst diff --git a/frontend.rst b/frontend.rst index 7dab845044d..3196004fdf4 100644 --- a/frontend.rst +++ b/frontend.rst @@ -56,6 +56,7 @@ Guides * :doc:`jQuery and Legacy Applications ` * :doc:`Passing Information from Twig to JavaScript ` * :doc:`webpack-dev-server and Hot Module Replacement (HMR) ` +* :doc:`Adding custom loaders ` Full API ........ diff --git a/frontend/encore/custom-loaders.rst b/frontend/encore/custom-loaders.rst new file mode 100644 index 00000000000..c9639bbdc89 --- /dev/null +++ b/frontend/encore/custom-loaders.rst @@ -0,0 +1,39 @@ +Adding Custom Loaders +===================== + +Encore already comes with a variety of different loaders that you can use out of the box, +but if there is a specific loader that you want to use that is not currently supported, then you +can easily add your own loader through the ``addLoader`` function. +The ``addLoader`` takes any valid webpack rules config. + +If, for example, you want to add the `handlebars-loader`_, you can just ``addLoader`` with +your loader config + +.. code-block:: javascript + + Encore + // ... + .addLoader({ test: /\.handlebars$/, loader: 'handlebars-loader' }) + +Since the loader config accepts any valid Webpack rules object, you can pass any +additional information your need for the loader + +.. code-block:: twig + + Encore + // ... + .addLoader( + { + test: /\.handlebars$/, + loader: 'handlebars-loader', + query: { + helperDirs: [ + __dirname + '/helpers1', + __dirname + '/helpers2', + ], + partialDirs: [ + path.join(__dirname, 'templates', 'partials') + ] + } + } + ) \ No newline at end of file From e08a1328bd7e7048ebf0c2bca7d4c13a5b4d4369 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Sat, 24 Jun 2017 16:04:19 +0200 Subject: [PATCH 2/2] Add missing link to handlebars-loader --- frontend/encore/custom-loaders.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/encore/custom-loaders.rst b/frontend/encore/custom-loaders.rst index c9639bbdc89..5bd395c10e5 100644 --- a/frontend/encore/custom-loaders.rst +++ b/frontend/encore/custom-loaders.rst @@ -36,4 +36,6 @@ additional information your need for the loader ] } } - ) \ No newline at end of file + ) + +.. _`handlebars-loader`: https://github.com/pcardune/handlebars-loader \ No newline at end of file