Adding Custom Loaders & Plugins

Adding Custom Loaders & Plugins

Adding Custom Loaders

Encore already comes with a variety of different loaders out of the box, but if there is a specific loader that you want to use that is not currently supported, you can 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, call addLoader with your loader config

  1. Encore
  2. // ...
  3. .addLoader({ test: /\.handlebars$/, loader: 'handlebars-loader' })
  4. ;

Since the loader config accepts any valid Webpack rules object, you can pass any additional information your need for the loader

  1. Encore
  2. // ...
  3. .addLoader({
  4. test: /\.handlebars$/,
  5. loader: 'handlebars-loader',
  6. options: {
  7. helperDirs: [
  8. __dirname + '/helpers1',
  9. __dirname + '/helpers2',
  10. ],
  11. partialDirs: [
  12. path.join(__dirname, 'templates', 'partials')
  13. ]
  14. }
  15. })
  16. ;

Adding Custom Plugins

Encore uses a variety of different plugins internally. But, you can add your own via the addPlugin() method. For example, if you use Moment.js, you might want to use the IgnorePlugin (see moment/moment#2373):

  1. // webpack.config.js
  2. + var webpack = require('webpack');
  3. Encore
  4. // ...
  5. + .addPlugin(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/))
  6. ;

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.