Skip to content

Commit

Permalink
docs: add asyncfunction support in the readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
EslamHiko committed Mar 31, 2020
1 parent 586b15a commit c6591c9
Showing 1 changed file with 50 additions and 7 deletions.
57 changes: 50 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ module.exports = {

## Options

| Name | Type | Default | Description |
| :---------------------------------: | :-----------------: | :------------------------------------------: | :----------------------------------------------- |
| **[`attributes`](#attributes)** | `{Boolean\|Object}` | `true` | Enables/Disables attributes handling |
| **[`preprocessor`](#preprocessor)** | `{Function}` | `undefined` | Allows pre-processing of content before handling |
| **[`minimize`](#minimize)** | `{Boolean\|Object}` | `true` in production mode, otherwise `false` | Tell `html-loader` to minimize HTML |
| **[`esModule`](#esmodule)** | `{Boolean}` | `false` | Use ES modules syntax |
| Name | Type | Default | Description |
| :---------------------------------: | :-------------------------: | :------------------------------------------: | :----------------------------------------------: |
| **[`attributes`](#attributes)** | `{Boolean\|Object}` | `true` | Enables/Disables attributes handling |
| **[`preprocessor`](#preprocessor)** | `{Function\|AsyncFunction}` | `undefined` | Allows pre-processing of content before handling |
| **[`minimize`](#minimize)** | `{Boolean\|Object}` | `true` in production mode, otherwise `false` | Tell `html-loader` to minimize HTML |
| **[`esModule`](#esmodule)** | `{Boolean}` | `false` | Use ES modules syntax |

### `attributes`

Expand Down Expand Up @@ -336,7 +336,7 @@ module.exports = {

### `preprocessor`

Type: `Function`
Type: `Function|AsyncFunction`
Default: `undefined`

Allows pre-processing of content before handling.
Expand All @@ -352,6 +352,10 @@ Allows pre-processing of content before handling.
<div>
```

#### `Function`

You can set the `preprocessor` option as a `Function` instance.

**webpack.config.js**

```js
Expand Down Expand Up @@ -387,6 +391,45 @@ module.exports = {
};
```

#### `AsyncFunction`

You can set the `preprocessor` option as an Asynchronous Function (`AsyncFunction`) instance.

**webpack.config.js**

```js
const Handlebars = require('handlebars');

module.exports = {
module: {
rules: [
{
test: /\.hbs$/i,
loader: 'html-loader',
options: {
preprocessor: async (content, loaderContext) => {
let result;

try {
result = await Handlebars.compile(content)({
firstname: 'Value',
lastname: 'OtherValue',
});
} catch (error) {
await loaderContext.emitError(error);

return content;
}

return result;
},
},
},
],
},
};
```

### `minimize`

Type: `Boolean|Object`
Expand Down

0 comments on commit c6591c9

Please sign in to comment.