-
-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for async functions to preprocessor option #272
Changes from 3 commits
586b15a
c6591c9
f616cfe
0c4371b
4c1933e
67956b7
a3125b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,12 +50,12 @@ module.exports = { | |
|
||
## Options | ||
|
||
| Name | Type | Default | Description | | ||
| :---------------------------------: | :-----------------: | :------------------------------------------: | :----------------------------------------------- | | ||
| **[`attributes`](#attributes)** | `{Boolean\|Object}` | `true` | Enables/Disables attributes handling | | ||
| 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 | | ||
| **[`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` | ||
|
||
|
@@ -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 | ||
|
@@ -387,6 +391,44 @@ module.exports = { | |
}; | ||
``` | ||
|
||
You can also set the `preprocessor` option as an Asynchronous Function (`async Function`) instance. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
For example : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid space after |
||
|
||
**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; | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need |
||
### `minimize` | ||
|
||
Type: `Boolean|Object` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it is changed, if not new?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I added
:
in the last of --- under the description table which made the lint centralize the description 😅