htmls-webpack-plugin
Simple, flexible and fast html webpack plugin.
NOTE: v2 support webpack5, if you still using webpack4, please install htmls-webpack-plugin@v1.0.9
Features
- Simple and flexisble, you can almost controll anything of generate htmls, no need of setup lots of plugins.
- Support multiple htmls by default
- Fast, almost 20x faster then html-webpack-plugin for 20+ pages.
Install
npm i -D htmls-webpack-plugin
Usage
const HtmlsWebpackPlugin = require('htmls-webpack-plugin')
module.exports = {
plugins: [
new HtmlsWebpackPlugin({
beforeEmit: (compilation, compiler) => void,
afterEmit: (compilation, compiler) => void,
render: (file, params) => string | Promise<string>,
htmls: [{
src: '',
filename: '',
render: (file, params) => string | Promise<string>,
flushOnDev: boolean | string
params: () => object | () => Promise<object> | object
transformParams?: (params: Params) => Params & { [k: string]: any }
}],
flushOnDev: false,
publicPath: function | string',
// optional, custom params when rendering, could be an async function
params: () => object | () => Promise<object> | object
// transformParams
transformParams?: (params: Params) => Params & { [k: string]: any }
})
]
}
The variables in html templates:
interface Params {
entries: string[]
files: string[]
jses: string[]
csses: string[]
options: Props
compilation: Compilation
[k: string]: any
}
ejs example
<body>
<% for (let js in entries) {%>
<script src="<%= js %>"></script>
<% } %>
</body>
Why not html-webpack-plugin
html-webpack-plugin is really hard to extends and slow for multiple htmls, too much complete features that I don't need. That's why I create this.
License
MIT