Use JSON schema to validate webpack configuration

Current behavior:

webpack constructor accepts any object and it will silently fail when it does not recognise a property, e.g.

const webpackConfig = {
  devtool: 'source-map',
  debug: true,
  context: __dirname,
  target: 'node',
  entry: {
    'app': [
      path.resolve(__dirname, './src')
    ]
  },
  pathinfo: true,
  output: {
    path: outputDir,
    filename: '[name].js'
  }
};

Looking at the above configuration, the error is not immediately obvious.

Expected/desired behavior:

Use http://json-schema.org/ to enforce webpack configuration.

In the above example, an error would be raised since pathinfo property belongs to the output object.

What is the motivation / use case for changing the behavior?

To prevent unintentional configuration silently failing.

Author: Fantashit

1 thought on “Use JSON schema to validate webpack configuration

Comments are closed.