diff --git a/README.md b/README.md index 7f856a8f9..b8791f0f2 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ The middleware accepts an `options` Object. The following is a property referenc Type: `Array` Default: `[ 'GET', 'HEAD' ]` -This property allows a user to pass the list of HTTP request methods accepted by the server. +This property allows a user to pass the list of HTTP request methods accepted by the middleware\*\*. ### headers @@ -107,26 +107,20 @@ For more information about `publicPath`, please see [the webpack documentation]( Type: `Boolean` Default: `undefined` -Instructs the module to enable or disable the server-side rendering mode. Please -see [Server-Side Rendering](#server-side-rendering) for more information. +Instructs the module to enable or disable the server-side rendering mode. +Please see [Server-Side Rendering](#server-side-rendering) for more information. ### writeToDisk Type: `Boolean|Function` Default: `false` -If `true`, the option will instruct the module to write files to the configured -location on disk as specified in your `webpack` config file. _Setting -`writeToDisk: true` won't change the behavior of the `webpack-dev-middleware`, -and bundle files accessed through the browser will still be served from memory._ -This option provides the same capabilities as the -[`WriteFilePlugin`](https://github.com/gajus/write-file-webpack-plugin/pulls). - -This option also accepts a `Function` value, which can be used to filter which -files are written to disk. The function follows the same premise as -[`Array#filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) -in which a return value of `false` _will not_ write the file, and a return value -of `true` _will_ write the file to disk. eg. +If `true`, the option will instruct the module to write files to the configured location on disk as specified in your `webpack` config file. +_Setting `writeToDisk: true` won't change the behavior of the `webpack-dev-middleware`, and bundle files accessed through the browser will still be served from memory._ +This option provides the same capabilities as the [`WriteFilePlugin`](https://github.com/gajus/write-file-webpack-plugin/pulls). + +This option also accepts a `Function` value, which can be used to filter which files are written to disk. +The function follows the same premise as [`Array#filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) in which a return value of `false` _will not_ write the file, and a return value of `true` _will_ write the file to disk. eg. ```js const webpack = require('webpack'); diff --git a/src/options.json b/src/options.json index eeb27dd1a..f5d9a0baf 100644 --- a/src/options.json +++ b/src/options.json @@ -2,9 +2,11 @@ "type": "object", "properties": { "mimeTypes": { + "description": "Allows a user to register custom mime types or extension mappings.", "type": "object" }, "writeToDisk": { + "description": "Allows to write generated files on disk.", "anyOf": [ { "type": "boolean" @@ -15,30 +17,47 @@ ] }, "methods": { + "description": "Allows to pass the list of HTTP request methods accepted by the middleware.", "type": "array", "items": { - "type": "string" + "type": "string", + "minlength": "1" } }, "headers": { "type": "object" }, "publicPath": { - "type": "string" + "description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.", + "anyOf": [ + { + "enum": ["auto"] + }, + { + "type": "string" + }, + { + "instanceof": "Function" + } + ] }, "serverSideRender": { + "description": "Instructs the module to enable or disable the server-side rendering mode.", "type": "boolean" }, "outputFileSystem": { + "description": "Set the default file system which will be used by webpack as primary destination of generated files.", "type": "object" }, "index": { + "description": "Allows to serve an index of the directory.", "anyOf": [ { "type": "boolean" }, { - "type": "string" + "type": "string", + "minlength": "1" } ] } diff --git a/test/__snapshots__/validation-options.test.js.snap b/test/__snapshots__/validation-options.test.js.snap index e88d5b1a8..891567ffe 100644 --- a/test/__snapshots__/validation-options.test.js.snap +++ b/test/__snapshots__/validation-options.test.js.snap @@ -10,6 +10,7 @@ exports[`validation should throw an error on the "index" option with "{}" value "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - options.index should be one of these: boolean | string + -> Allows to serve an index of the directory. Details: * options.index should be a boolean. * options.index should be a string." @@ -19,6 +20,7 @@ exports[`validation should throw an error on the "index" option with "0" value 1 "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - options.index should be one of these: boolean | string + -> Allows to serve an index of the directory. Details: * options.index should be a boolean. * options.index should be a string." @@ -27,46 +29,59 @@ exports[`validation should throw an error on the "index" option with "0" value 1 exports[`validation should throw an error on the "methods" option with "{}" value 1`] = ` "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - options.methods should be an array: - [string, ...]" + [string, ...] + -> Allows to pass the list of HTTP request methods accepted by the middleware." `; exports[`validation should throw an error on the "methods" option with "true" value 1`] = ` "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - options.methods should be an array: - [string, ...]" + [string, ...] + -> Allows to pass the list of HTTP request methods accepted by the middleware." `; exports[`validation should throw an error on the "mimeTypes" option with "foo" value 1`] = ` "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - options.mimeTypes should be an object: - object { … }" + object { … } + -> Allows a user to register custom mime types or extension mappings." `; exports[`validation should throw an error on the "outputFileSystem" option with "false" value 1`] = ` "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - options.outputFileSystem should be an object: - object { … }" + object { … } + -> Set the default file system which will be used by webpack as primary destination of generated files." `; exports[`validation should throw an error on the "publicPath" option with "false" value 1`] = ` "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - - options.publicPath should be a string." + - options.publicPath should be one of these: + \\"auto\\" | string | function + -> The \`publicPath\` specifies the public URL address of the output files when referenced in a browser. + Details: + * options.publicPath should be \\"auto\\". + * options.publicPath should be a string. + * options.publicPath should be an instance of function." `; exports[`validation should throw an error on the "serverSideRender" option with "0" value 1`] = ` "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - - options.serverSideRender should be a boolean." + - options.serverSideRender should be a boolean. + -> Instructs the module to enable or disable the server-side rendering mode." `; exports[`validation should throw an error on the "serverSideRender" option with "foo" value 1`] = ` "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - - options.serverSideRender should be a boolean." + - options.serverSideRender should be a boolean. + -> Instructs the module to enable or disable the server-side rendering mode." `; exports[`validation should throw an error on the "writeToDisk" option with "{}" value 1`] = ` "Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema. - options.writeToDisk should be one of these: boolean | function + -> Allows to write generated files on disk. Details: * options.writeToDisk should be a boolean. * options.writeToDisk should be an instance of function." diff --git a/test/validation-options.test.js b/test/validation-options.test.js index 5067902f1..7a475cbe8 100644 --- a/test/validation-options.test.js +++ b/test/validation-options.test.js @@ -21,7 +21,14 @@ describe('validation', () => { failure: [true], }, publicPath: { - success: ['/foo'], + success: [ + '/foo', + '', + 'auto', + () => { + return '/public/path'; + }, + ], failure: [false], }, serverSideRender: {