1.1.0 • Published 8 years ago

webpack-config-validationscheme v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

webpack-config-validationscheme

Validate your webpack configs with joi

dependencies devDependencies version downloads MIT License PRs Welcome Commitizen friendly semantic-release

Writing webpack configs is brittle and error-prone. This package provides a joi object schema for webpack configs. This gets you a) static type safety, b) property spell checking and c) semantic validations such as "loader and loaders can not be used simultaneously" or "query can only be used with loader, not with loaders".

You're very welcome to give feedback & PR's.

Example

Take this simple webpack config. It has a tiny, hard to spot error. Can you find it?

var config = {
  module: {
    loaders: [
      { test: /\.js$/, loaders: 'babel-loader', exclude: /node_modules/ }
    ]
  },
  output: {
    library: 'Redux',
    libraryTarget: 'umd'
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(env)
    })
  ]
};

webpack-config-validationscheme makes it easy:

validation-example

Usage

var scheme = require('webpack-config-validationscheme')
var Joi = require('webpack-config-validationscheme').Joi
var webpackConfig = require('pathToYourConfig')

var validationResult = Joi.validate(webpackConfig, scheme, { abortEarly: false })
  if (validationResult.error) {
    console.info(validationResult.error.annotate())
  } else {
    console.info('Config is valid.'))
  }

Customizing

If you need to extend the schema, for example for custom top level properties or properties added by third party plugins like eslint-loader (which adds a toplevel eslint property), do it like this:

var scheme = require('webpack-config-validationscheme')
var Joi = require('webpack-config-validationscheme').Joi
var webpackConfig = require('pathToYourConfig')

var yourScheme = scheme.concat(Joi.object({
  // this would just allow the property and doesn't perform any additional validation
  eslint: Joi.any()
}))

Support

Because this module uses the amazing Joi validation library, this module only supports Node >=4.0.0.

License

MIT