Skip to content

extensibility

benholloway edited this page Mar 31, 2016 · 4 revisions

Amending the definitions

You may call the define() method to adjust the structure at any time. You do not need to edit this package.

To adjust all modes, you would append() an operation to the common definition. This may be done at any time before resolve() is called.

module.exports = angularity(...)
  .define('common')
    .append(additional)
  ...
  .resolve();

function additional(configurator, options) {
  return configurator
    .merge(...);
}

If you want to adjust the configuration for a specific mode, you would append() and operation to the definition of that same mode. This may be done at any time before resolve() is called.

module.exports = angularity(...)
  .define('test')
    .append(additional)
  ...
  .resolve();

function additional(configurator, options) {
  return configurator
    .merge(...);
}

Each operation is passed the existing configurator, and the final (merged) options . It should return a configurator, usually the same instance as that provided.

For more details refer to the webpack-multi-configurator documentation on definition.

For specific examples refer to the how do I ...? documentation.

Operator short form

If you are performing simple mutations then you may use any of the webpack-configurator methods directly on the definition.

For example, the common example above becomes:

module.exports = angularity(...)
  .define('common')
    .merge(...)
  ...
  .resolve();

And the test example above becomes:

module.exports = angularity(...)
  .define('test')
    .merge(...)
  ...
  .resolve();

The up side is that the additional function is generated and append()ed automatically.

The down side is you do not have access to the final (merged) options.

Customising the configurator

By changing the factory function you can add custom methods to the webpack-configurator instance.

You may do so by calling the create() method. This method normally is used to refine options, but it may also be passed a new factory function.

Interestingly the export from this package is actually the create() function. So you can use the initial invocation or call create() at any time following.

If you specify a new factory function it will be passed the previous factory, and the final (merged) options. In this way you can redefine the webpack-configurator instance to your liking.

In the following example we first extend the configurator with foo() and then extend it with bar().

module.exports = angularity({...}, newFactory)
  ...
  .create({...}, newerFactory)
  ...
  .resolve();

function newFactory(internalFactory, options) {
  var configurator = internalFactory();
  configurator.foo = function foo(){};
  return configurator;
}

function newerFactory(newFactory, options) {
  var configurator = newFactory();
  configurator.bar = function bar(){};
  return configurator;
}

For more information refer to the webpack-multi-configurator documentation on create.

Clone this wiki locally