Skip to content

Commit 3d9905e

Browse files
pierredupweaverryan
authored andcommitted
Add docs for custom loaders
1 parent 7983f69 commit 3d9905e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

frontend.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Guides
5858
* :doc:`jQuery and Legacy Applications </frontend/encore/legacy-apps>`
5959
* :doc:`Passing Information from Twig to JavaScript </frontend/encore/server-data>`
6060
* :doc:`webpack-dev-server and Hot Module Replacement (HMR) </frontend/encore/dev-server>`
61+
* :doc:`Adding custom loaders </frontend/encore/custom-loaders>`
6162

6263
Full API
6364
........

frontend/encore/custom-loaders.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Adding Custom Loaders
2+
=====================
3+
4+
Encore already comes with a variety of different loaders that you can use out of the box,
5+
but if there is a specific loader that you want to use that is not currently supported, then you
6+
can easily add your own loader through the ``addLoader`` function.
7+
The ``addLoader`` takes any valid webpack rules config.
8+
9+
If, for example, you want to add the `handlebars-loader`_, you can just ``addLoader`` with
10+
your loader config
11+
12+
.. code-block:: javascript
13+
14+
Encore
15+
// ...
16+
.addLoader({ test: /\.handlebars$/, loader: 'handlebars-loader' })
17+
18+
Since the loader config accepts any valid Webpack rules object, you can pass any
19+
additional information your need for the loader
20+
21+
.. code-block:: twig
22+
23+
Encore
24+
// ...
25+
.addLoader(
26+
{
27+
test: /\.handlebars$/,
28+
loader: 'handlebars-loader',
29+
query: {
30+
helperDirs: [
31+
__dirname + '/helpers1',
32+
__dirname + '/helpers2',
33+
],
34+
partialDirs: [
35+
path.join(__dirname, 'templates', 'partials')
36+
]
37+
}
38+
}
39+
)

0 commit comments

Comments
 (0)