|
| 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 |
0 commit comments