Skip to content

Commit 807b83f

Browse files
committed
[Encore] Documenting addPlugin - see #8070
1 parent a099bff commit 807b83f

File tree

3 files changed

+65
-42
lines changed

3 files changed

+65
-42
lines changed

frontend.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +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>`
61+
* :doc:`Adding custom loaders & plugins </frontend/encore/custom-loaders-plugins>`
6262
* :doc:`Advanced Webpack Configuration </frontend/encore/advanced-config>`
6363

6464
Troubleshooting
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Adding Custom Loaders & Plugins
2+
===============================
3+
4+
Adding Custom Loaders
5+
---------------------
6+
7+
Encore already comes with a variety of different loaders out of the box,
8+
but if there is a specific loader that you want to use that is not currently supported, you
9+
can add your own loader through the ``addLoader`` function.
10+
The ``addLoader`` takes any valid webpack rules config.
11+
12+
If, for example, you want to add the `handlebars-loader`_, call ``addLoader`` with
13+
your loader config
14+
15+
.. code-block:: javascript
16+
17+
Encore
18+
// ...
19+
.addLoader({ test: /\.handlebars$/, loader: 'handlebars-loader' })
20+
;
21+
22+
Since the loader config accepts any valid Webpack rules object, you can pass any
23+
additional information your need for the loader
24+
25+
.. code-block:: javascript
26+
27+
Encore
28+
// ...
29+
.addLoader({
30+
test: /\.handlebars$/,
31+
loader: 'handlebars-loader',
32+
query: {
33+
helperDirs: [
34+
__dirname + '/helpers1',
35+
__dirname + '/helpers2',
36+
],
37+
partialDirs: [
38+
path.join(__dirname, 'templates', 'partials')
39+
]
40+
}
41+
})
42+
;
43+
44+
Adding Custom Plugins
45+
---------------------
46+
47+
Encore uses a variety of different `plugins`_ internally. But, you can add your own
48+
via the ``addPlugin()`` method. For example, if you use `Moment.js`_, you might want
49+
to use the `IgnorePlugin`_ (see `moment/moment#2373`_):
50+
51+
.. code-block:: diff
52+
53+
// webpack.config.js
54+
Encore
55+
// ...
56+
57+
+ .addPlugin(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/))
58+
;
59+
60+
.. _`handlebars-loader`: https://github.com/pcardune/handlebars-loader
61+
.. _`plugins`: https://webpack.js.org/plugins/
62+
.. _`Moment.js`: https://momentjs.com/
63+
.. _`IgnorePlugin`: https://webpack.js.org/plugins/ignore-plugin/
64+
.. _`moment/moment#2373`: https://github.com/moment/moment/issues/2373

frontend/encore/custom-loaders.rst

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)