https://github.com/hmpl-language/hmpl-loader
Loader for files with hpml extension for Webpack
https://github.com/hmpl-language/hmpl-loader
hmpl hmpl-js loader webpack webpack-loader webpack-loaders
Last synced: 4 months ago
JSON representation
Loader for files with hpml extension for Webpack
- Host: GitHub
- URL: https://github.com/hmpl-language/hmpl-loader
- Owner: hmpl-language
- License: mit
- Created: 2024-11-05T18:43:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-15T20:18:42.000Z (8 months ago)
- Last Synced: 2025-11-15T22:07:08.112Z (8 months ago)
- Topics: hmpl, hmpl-js, loader, webpack, webpack-loader, webpack-loaders
- Language: JavaScript
- Homepage: https://hmpl-lang.dev/webpack
- Size: 14.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hmpl-loader
[](https://www.npmjs.com/package/hmpl-loader)
This loader was created for files with the `.hmpl` extension, which are converted using the [hmpl-js](https://www.npmjs.com/package/hmpl-js) package. This loader is designed for webpack.
> Loader works with hmpl-js version 1.0.4 or higher
## Installation
```bash
npm i -D hmpl-loader
```
## Usage:
In the `webpack.config.js` file you can specify the following lines of code:
```javascript
module.exports = {
module: {
rules: [
{
test: /\.hmpl$/i,
use: ["hmpl-loader"],
},
],
},
};
```
After `webpack.config.js` has been changed, in js files (for example, in `main.js`), you can import a file with the `.hmpl` extension and receive a [template function](https://hmpl-lang.dev/functions/template/) in response.
### main.hmpl
```hmpl
{{#request src="/api/test"}}
{{/request}}
```
### main.js
```javascript
const templateFn = require("./main.hmpl");
const elementObj = templateFn();
```
## Options
The loader supports the compile function options.
```javascript
module.exports = {
module: {
rules: [
{
test: /\.hmpl$/i,
use: {
loader: "hmpl-loader",
options: {
memo: true,
autoBody: { formData: true },
allowedContentTypes: ["text/html"],
disallowedTags: ["script"],
sanitize: false,
sanitizeConfig: { USE_PROFILES: { html: true } },
},
},
},
],
},
};
```
The list of options is described in the documentation [here](https://hmpl-lang.dev/objects/hmpl/#compile).
## Changelog
[Changelog](https://github.com/hmpl-language/hmpl-loader/releases)
## License
[Licensed under MIT](https://github.com/hmpl-language/hmpl-loader/blob/master/LICENSE)