Home Reference Source
public class | source

ConfigurationBuilder

The configuration builder class

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

Define aliases

public

Returns a plain JavaScript object representing the built Webpack configuration

public

Set the output directory

public

Turns on overlay and optional proxy

public

Specify whether or not to generate development configuration

public

Add resolvable extensions (ex: '.jsx', '.css')

public

externals(depsOrFiles: string | string[], moduleType: string): *

Exclude certain modules/files from the bundle

public

Add a loader

public

Merge configuration using webpack-merge

public

Add plugins

public

Specify whether or not to generate production configuration

public

Set entry/entries based on glob(s)

public

Specify vendor modules

Public Constructors

public constructor() source

Public Methods

public alias(aliases: object): ConfigurationBuilder source

Define aliases

Params:

NameTypeAttributeDescription
aliases object

The alias specifications

Example:

// webpack.config.js
module.exports = builder()
  .alias({
    'react': 'inferno-compat',
    'react-dom': 'inferno-compat',
  })
  .build()

See:

public build(): object source

Returns a plain JavaScript object representing the built Webpack configuration

Return:

object

Example:

// webpack.config.js
module.exports = builder()
  .build()

public dest(dir: string, chunkhash: boolean): ConfigurationBuilder source

Set the output directory

Params:

NameTypeAttributeDescription
dir string

The output directory; this path may be relative or absolute

chunkhash boolean
  • default: true

Whether to include [chunkhash] in the filename

Example:

// webpack.config.js
module.exports = builder()
  .dest('build/public/js', false)
  .build()

public devServer(opts: Object): ConfigurationBuilder source

Turns on overlay and optional proxy

Params:

NameTypeAttributeDescription
opts Object

(plus optional 'proxy' options to be passed to 'http-proxy')

Example:

// webpack.config.js
module.exports = builder()
  .devServer({
    publicPath: '/js/',
    proxy: {
      target: 'https://localhost:8443/',
      secure: false,
    },
  })
  .build()

public development(enable: boolean): ConfigurationBuilder source

Specify whether or not to generate development configuration

Params:

NameTypeAttributeDescription
enable boolean

Whether or not to enable development mode

Example:

// webpack.config.js
module.exports = builder()
  .development((process.env.NODE_ENV || 'development') == 'development')
  .build()

public extensions(ext: ...string): ConfigurationBuilder source

Add resolvable extensions (ex: '.jsx', '.css')

Params:

NameTypeAttributeDescription
ext ...string

The extensions to add

Example:

// webpack.config.js
module.exports = builder()
  .extensions('.js', '.jsx', '.ts', '.css', '.less', '.scss')
  .build()

See:

public externals(depsOrFiles: string | string[], moduleType: string): * source

Exclude certain modules/files from the bundle

Params:

NameTypeAttributeDescription
depsOrFiles string | string[]

The array of files/module to exclude

moduleType string

see: https://webpack.js.org/configuration/externals/#externals

Return:

*

Example:

module.exports = builder()
  .externals(Object.keys(require('./package').dependencies))
  .build()

// Exclude specific file:

module.exports = builder()
  // Note how we are using 'config/index' and not 'config/index.js'
  // Be sure to match exactly how you are requiring/importing the file
  // For example, if you require the file with `require('./config/index')`
  // then exclude 'config/index' (without extension).  However if your code
  // looks like `require('./config/index.js')`, then exclude 'config/index.js'
  .externals(path.resolve('config/index'))
  .build()

public loader(ext: string | Array<string>, loader: string | Array<string>, query: object): ConfigurationBuilder source

Add a loader

Params:

NameTypeAttributeDescription
ext string | Array<string>

The file extensions to match

loader string | Array<string>

The loader spec

query object
  • nullable: true

The loader parameters

Example:

// webpack.config.js
module.exports = builder()
  .loader(['.js', '.jsx'], 'babel-loader', {
    presets: ['latest', 'react'],
  })
  .build()

See:

public merge(cfgs: ...object): ConfigurationBuilder source

Merge configuration using webpack-merge

Params:

NameTypeAttributeDescription
cfgs ...object

The configurations to merge

Example:

// webpack.config.js
module.exports = builder()
  .merge({
    resolve: {
      modules: ['node_modules'],
    },
  })
  .build()

See:

public plugins(plugins: ...object): ConfigurationBuilder source

Add plugins

Params:

NameTypeAttributeDescription
plugins ...object

The plugins to add

Example:

// webpack.config.js
module.exports = builder()
  .plugins(new Plugin1(), new Plugin2())
  .build()

public production(enable: boolean): ConfigurationBuilder source

Specify whether or not to generate production configuration

Params:

NameTypeAttributeDescription
enable boolean

Whether or not to enable production mode

Example:

// webpack.config.js
module.exports = builder()
  .production(process.env.NODE_ENV == 'production')
  .build()

public src(globs: ...string): ConfigurationBuilder source

Set entry/entries based on glob(s)

Params:

NameTypeAttributeDescription
globs ...string

The file globs

Example:

// webpack.config.js
module.exports = builder()
  .src('src/*.js')
  .build()

public vendor(modules: ...string): ConfigurationBuilder source

Specify vendor modules

Params:

NameTypeAttributeDescription
modules ...string

The vendor modules

Example:

// webpack.config.js
module.exports = builder()
  .vendor('react', 'react-dom', ...)
  .build()