compose Function

The primary routine of mortal-webpack: turn a bunch of build directives into a webpack configuration object.

Example usage:

const { compose, builders: b } = require('mortal-webpack')

const webpackConfig = compose([
  b.output({ path: 'dist/' }),

  b.generateCommonBundle({
    name: 'vendor',
    modules: [ 'lodash', 'react' ]
  }),

  b.generateBundle({
    name: 'application',
    modules: [ 'src/index.js' ]
  })
])

Signature

compose(options: Object, directives: Array.<Directive>) -> Config|InvalidConfig

Parameters (3)

options
Object
options.happyPackOptions
Object?

If you choose to enable happypack for compiling then you should pass the common options to the plugins here, like threadPool: HappyThreadPool or threads: Number.

directives
Array.<Directive>

The list of directives that describe what the configuration should contain.

This list is flattened before consumption in order to allow for builders and macros to return multiple directives from the same API.

For example, the following two calls are equivalent:

compose([
  [ b.output({}) ]
])

compose([
  b.output({})
])

Please keep in mind that every item in this list must be a builders~Directive and can not be falsey; if you need to conditionally add a directive, use helpers like builders.when and builders.whenEnv.

compose([
  // OK:
  b.when(someCondition, [
b.devTool('eval')
  ])

  // NOT OK! don't do this
  someCondition && [
b.devTool('eval')
  ]
])

The reason for this is that we always want to evaluate the directives to make the output more predictable. Short-circuiting using the && operator prohibits us from doing that.

Return Value

Config|InvalidConfig

The configuration object that can be passed to webpack.

In the case of an error, an instance of InvalidConfig will be returned which you can utilize to let the user know what went wrong.