Webpkr API

webpkr = require('webpkr');

webpkr( opts )

Creates a new instance of Webpkr with the supplied options and calls buildFile() on it and returns the resulting webpack configuration.

class webpkr.Webpkr

constructor( opts )

opts.config

{String}

webpkr initialization module

./webpkr

opts.projectDir

{String}

project directory

process.cwd()

opts.buildDir

{String}

directory where output is written

projectDir/build

opts.environments

{String[]}

node.js environments

['development', 'production', 'testing', 'staging']

Members

compile(closure)

Compiles the supplied DSL build script into a configuration tree.

closure

{Function}

the build script

returns

{Object}

configuration tree

Example
const { Webpkr } = require( '../' );
const webpkr = new Webpkr();

const tree = webpkr.compile( () => {
  context( projectDir )
  entry( './src/index.js' )
  output( () => {
    filename( 'bundle.js' )
    path$( 'dist' )
  } )
} )

// print configuration tree
console.log( tree.toAsciiTree() );
Output
└─webpackConfig, WebpackNodeExt, webpackConfig, [ undefined ]
  ├─context, ContextNodeExt, context, [ '/Users/venkat/proj/repos...'
  ├─entry, EntryNodeExt, entry, [ './src/index.js' ]
  └─output, OutputNodeExt, output, [ undefined ]
    ├─filename, FilenameNodeExt, node.__filename, [ 'bundle.js' ]
    └─path$, PathNodeExt, output.path, [ 'dist' ]

compileFile( file )

Loads the DSL build script from the supplied file and returns the compiled configuration tree. Relative paths are resolved from projectDir.

file

{String}

path to the build script

returns

{Object}

configuration tree

buildFile(file)

Loads the DSL build script from the supplied file, builds it and returns a Function which can be passed to webpack.

file

{String}

path to the build script

returns

{Function}

webpack configuration

The returned Function accepts a single parameter. The webpack CLI uses this parameter to pass commandline arguments set via --env to the configuration script. These arguments are avilable via a global object cliArgs.
When using the webpack Node API, the function must be called and the resulting object should be passed to webpack().

Events

afterCompile

Emitted after the DSL is compiled into a configuration tree. The tree is passed as the only argument to the event.

afterNodeEvaluate

Emitted during the evaluation phase, after each node is evaluated. The current node and its evaluated value are passed as arguments.

afterEvaluate

Emitted after the entire configuration tree is evaluated. The final webpack configuration object is passed as the only argument.